シェル スクリプトを使用して、grep コマンドで次の 2 つのオプションのいずれかを実行する方法を探しています。
a) grep コマンドを使用して、ファイル内の次の 10 行の一致を表示します。つまり、このコマンドgrep "pattern" file.txt
は、そのパターンを持つファイルのすべての行になります。
patternrestoftheline
patternrestofanotherline
patternrestofanotherline
...
だから私はこれを探しています:
patternrestoftheline
following line
following line
...
until the tenth
patternrestofanotherline
following line
following line
...
until the tenth
b) grep コマンドを使用して、2 つのパターン内のすべての行を境界であるかのように表示します。
patternA restoftheline
anotherline
anotherline
...
patternB restoftheline
grep の代わりに別のコマンドがより適切なオプションであるかどうかはわかりません。私は現在、問題を解決するループを使用していますが、行単位であるため、非常に大きなファイルでは時間がかかりすぎます。
Solaris で動作するソリューションを探しています。助言がありますか?