2つの開き括弧の間の内容をgrep

2つの開き括弧の間の内容をgrep

これは私がアクセスしたいファイルの出力です。

[1]
RsyncCommand: 0
Number of files: 18
Number of files transferred: 0
Total file size: 24.01M bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 354
File list generation time: 0.002 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 424
Total bytes received: 69
total size is 24.01M  speedup is 48701.73 (DRY RUN)


[2]
RsyncCommand: 0
Number of files: 21
Number of files transferred: 0
Total file size: 5.22M bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 507
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 586
Total bytes received: 78
total size is 5.22M  speedup is 7862.54 (DRY RUN)


[3]
RsyncCommand: 0
Number of files: 54
Number of files transferred: 0
Total file size: 63.67M bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 1.56K
File list generation time: 0.002 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 1.75K
Total bytes received: 185
total size is 63.67M  speedup is 32988.24 (DRY RUN)

2をgrepすると出力が欲しい

[2]
RsyncCommand: 0
Number of files: 21
Number of files transferred: 0
Total file size: 5.22M bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 507
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 586
Total bytes received: 78
total size is 5.22M  speedup is 7862.54 (DRY RUN)

grepコマンドを使用して次の出力をどのように表示できますか?

答え1

次のようにgrepを使用できます-A

$ grep -A 13 '^\[2\]' inputfile.txt

-A一致後に含める行数を指定します。

sedしかし、この場合は、以下を使用する方が良いと思います。

$ sed -n '/^\[2\]/,/^$/p' inputfile.txt

[2]これにより、空白行の間のすべての内容が印刷されます。

また、以下を使用してくださいawk

$ awk -v RS='' -v ORS='\n\n' '/^\[2\]/' inputfile.txt

関連情報