Jump to content

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

added AWK
(Added Python implementation)
(added AWK)
Line 97:
saying 'Nice Doggy'
"Diplomacy is the art of
</pre>
=={{header|AWK}}==
<lang AWK>
# syntax: GAWK -f REVERSE_THE_ORDER_OF_LINES_IN_A_TEXT_FILE_WHILE_PRESERVING_THE_CONTENTS_OF_EACH_LINE.AWK filename
{ arr[NR] = $0 }
END {
for (i=NR; i>=1; i--) {
printf("%s\n",arr[i])
}
exit(0)
}
</lang>
{{out}}
<pre>
--- Will Rodgers
 
until you can find a rock."
saying 'Nice Doggy'
"Diplomacy is the art of
</pre>
 
477

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.