I'd like to reverse the order of lines in a text file (or stdin), preserving the contents of each line.
So, i.e., starting with:
foo bar baz
I'd like to end up with
baz bar foo
Is there a standard UNIX commandline utility for this?
command! -bar -range=% Reverse <line1>,<line2>g/^/m0|nohl " REVERSE line ordering, and move those lines to the top of the file.
the -r flag is an option of the sort command which sorts the input file in reverse order i.e. descending order by default.
Also worth mentioning: tac
(the, ahem, reverse of cat
). Part of coreutils.
tac a.txt > b.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With