Reverse the order of lines in a text file while preserving the contents of each line: Difference between revisions

Content added Content deleted
(Ada version)
(Added Python implementation)
Line 316: Line 316:
</pre>
</pre>


=={{header|Python}}==
Interactive program which takes input from a file :
<lang python>
#Aamrun, 4th October 2021

import sys

if len(sys.argv)!=2:
print("Usage : python " + sys.argv[0] + " <filename>")
exit()

dataFile = open(sys.argv[1],"r")

fileData = dataFile.read().split('\n')

dataFile.close()

[print(i) for i in fileData[::-1]]
</lang>
Input file :
<pre>
"Diplomacy is the art of
saying 'Nice Doggy'
until you can find a rock."
--- Will Rodgers
</pre>
Sample run and output:
{{out}}
<pre>

C:\My Projects\BGI>python rosetta7.py diplomaticQuote.txt
--- Will Rodgers

until you can find a rock."
saying 'Nice Doggy'
"Diplomacy is the art of

C:\My Projects\BGI>
</pre>
=={{header|R}}==
=={{header|R}}==
<lang R>text <- scan("Rodgers.txt", character(), sep = "\n")
<lang R>text <- scan("Rodgers.txt", character(), sep = "\n")