Find specific pattern and print complete text block using awk or sed

后端 未结 6 2298
离开以前
离开以前 2021-01-06 00:57

How can find a specific number in a text block and print the complete text block beginning with the key word \"BEGIN\" and ending with \"

6条回答
  •  Happy的楠姐
    2021-01-06 01:46

    This might work for you (GNU sed):

    sed -n '/^BEGIN/{x;d};H;/^END/{x;s/^B: 567/&/mp}' file
    

    or this:

    sed -n '/^BEGIN/!b;:a;$!{N;/\nEND/!ba};/\nB: 567/p' file
    

提交回复
热议问题