awk: Display matched regex (multiline)

后端 未结 2 1997
[愿得一人]
[愿得一人] 2020-12-22 08:38

I have a file that looks like this:

SF:/home/developer/project/test/resources/somefile.js
DA:1,2
DA:3,2
end_of_record
SF:/home/developer/project/src/resource         


        
相关标签:
2条回答
  • 2020-12-22 08:54
    awk '{if($0~/SF:.*\/test\//){P=1;}if($0~/end_of_record/&& P==1){print;P=0;}if(P==1)print}' your_file
    
    0 讨论(0)
  • 2020-12-22 08:57

    you need a flag:

    awk '/^SF.*test.*/{f=1}f;/end_of_record/{f=0}' yourFile
    
    0 讨论(0)
提交回复
热议问题