tac コマンド
tac というコマンドがあるのでそれを.こういうシンプル系のツール,知ってると便利に使えるのだが知らないと(シンプルな分)自分でスクリプト書いたりしがちなので,積極的に拾っていきたい.
NAME
tac - concatenate and print files in reverse
SYNOPSIS
tac [OPTION]... [FILE]...
DESCRIPTION
Write each FILE to standard output, last line first.
With no FILE, or when FILE is -, read standard input.ということで,ファイルを読み込んで逆順に出力.cat の逆で tac なんでしょうね.
オプションに -b, -s, -r があり,-s は newline じゃなくて任意の文字列で区切る,-r はそれの regex, -b はセパレータの場所を (after じゃなくて) before に規定する感じ.
$ cat cat.txt
Here comes the cat
there goes THE dog$ tac cat.txt
there goes THE dog
Here comes the cat$ tac -s " " cat.txt (. はスペース)
dog
THE goes cat
there the comes Here.$ tac -s " " -b cat.txt
.dog
.THE goes cat
there the comesHereなるほど.newline が混じってるから -s とかちょっとわかりにくいけど,まあそういうことだ.