Bash에서 문자열을 만난 후 다음 줄을 추출하는 방법

Nov 12 2020

예를 들어, 텍스트 파일 이름이 있습니다.

> "result_merge_file.txt"

병합되어 해당 파일에 보관되는 10 개의 서로 다른 파일의 로그를 보관합니다.

지금 나는 노력하고있다

특정 섹션을 추출

병합 된 로그 파일 "result_merge_file.txt"에서 다른 파일로 보냅니다.

"result_after_Extraction.txt"

> extract a certain section looks like following

PerformanceINFO                                             
            UVM_INFO_PERF ****NIB-FIB Axis Interface Per-packet Performance Report****                                             
             interface_name            : NIB-FIB,                                             
             date                      : NAN,                                             
             interface_description     : injection,                                             
             port_number               : 0,                                             
             clock_period (ps)         : 4850,                                             
             number_of_diff_packets    : 10,                                             
             payload_sizes (bytes)     : {312, 1100, 1132, 1404, 1666, 3100, 3610, 4998, 7922, 8544, }                                             
             packet_datarate (bits/clk): {116, 127, 125, 120, 119, 121, 124, 121, 124, 121, }
`

내가 지금까지 시도한 것은

grep -A3 -P '^PerformanceINFO$' temp_log.txt > result_after_Extraction.txt

그러나 빈 결과를 제공합니다

답변

1 AaronShang Nov 13 2020 at 07:04

PerformanceINFO라인은 후행 공백을하고있다, 정보에 종료되지 않습니다.

따라서 $표시를 제거 하거나

grep -A3 '^PerformanceINFO\s\+$'