다음은 내가 액세스하려는 파일의 출력입니다.
[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