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?
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?
Also worth mentioning:
tac
(the, ahem, reverse ofcat
). Part of coreutils.Flipping one file into another
I had the same question, but I also wanted the first line (header) to stay on top. So I needed to use the power of awk
PS also works in cygwin or gitbash
Best solution:
or
Try the following command:
The simplest method is using the
tac
command.tac
iscat
's inverse. Example: