tac flags & options

Basic usage

Print a file with lines in reverse order (last line first).

tac file.txt

Pipe usage

Reverse piped input.

seq 1 5 | tac

-s, --separator

Use a custom record separator instead of newline.

tac -s ',' data.txt

-r, --regex

Treat the separator as a regular expression.

tac -r -s '[.!?] ' text.txt

-b, --before

Attach the separator to the beginning of the record instead of the end.

tac -b -s '---' file.txt

View recent log entries first

tac /var/log/syslog | head -20

Reverse and save

tac file.txt > reversed.txt

Reverse words in a line

Combine with tr to reverse word order.

echo "one two three" | tr ' ' '\n' | tac | tr '\n' ' '