Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
grep の --max-count オプションは、ファイルの先頭から検索を開始し、フレーズが max-count 回発生したときに停止します。さて、フレーズの最後の n 回の出現を見つける必要がありますか?
どうすればいいのですか?
grep だけではできませんが、最初に tac を使用してファイルを元に戻すことができます。
$ tac file | grep --max-count=N foo
tac行の順序を逆にするために使用します (またはこれtail -rをサポートしている場合tail):
tac
tail -r
tail
tac your_input_file | grep --max-count=N search-phrase