I\'m writing a small shell script that needs to reverse the lines of a text file. Is there a standard filter command to do this sort of thing?
My specific applicatio
rev <name of your text file.txt>
You can even do this:
echo <whatever you want to type>|rev
There is a standard command for your purpose:
tail -r file.txt
prints the lines of file.txt in reverse order!
In GNU coreutils, there's tac(1)
Similar to the sed example above, using perl - maybe more memorable (depending on how your brain is wired):
perl -e 'print reverse <>'
Answer is not 42 but tac
.
Edit: Slower but more memory consuming using sed
sed 'x;1!H;$!d;x'
and even longer
perl -e'print reverse<>'
cat -b only numbers nonblank lines"
If that's the only issue you want to avoid, then why not use "cat -n" to number all the lines?