mokacoding

unit and acceptance testing, automation, productivity

How to reverse a file in the terminal

Today, I used grep to filter the git log output to only get the changes made on a certain value holding the version number for an app.

The git log output is sorted newest to oldest, but I was interested in how the changes progressed, that is, oldest to newest.

You can use tac to reverse a file or the standard input.

$ cat file.txt
a
b
c

$ tac file.txt
c
b
a

Here's how it works when used with a pipe.

echo "a\nb\nc" | tac
c
b
a

Want more of these posts?

Subscribe to receive new posts in your inbox.