tac
コマンド
tac
コマンドはファイルの行を逆にして出力します。
$ cat sample.txt
1 abcde
2 abcde
3 abcde
4 abcde
5 abcde
$ tac sample.txt
5 abcde
4 abcde
3 abcde
2 abcde
1 abcde
複数のファイルのそれぞれの行を逆にして連結する場合には次のように実行します。
sample.txt
$ cat sample.txt example.txt
1 abcde
2 abcde
3 abcde
4 abcde
5 abcde
a 12345
b 12345
c 12345
d 12345
e 12345
$ tac sample.txt example.txt
5 abcde
4 abcde
3 abcde
2 abcde
1 abcde
e 12345
d 12345
c 12345
b 12345
a 12345
複数のファイルを連結したうえで行を逆にして出力するには次のようにします。
$ cat sample.txt example.txt | tac
e 12345
d 12345
c 12345
b 12345
a 12345
5 abcde
4 abcde
3 abcde
2 abcde
1 abcde
rev
コマンド
rev
コマンドはファイルの行の文字列を逆にして出力します。
$ rev sample.txt
edcba 1
edcba 2
edcba 3
edcba 4
edcba 5
ファイル全体を末尾から先頭に向かって出力するには次のようにします。
$ tac sample.txt | rev
edcba 5
edcba 4
edcba 3
edcba 2
edcba 1