【SHELL】跨行内容查找、替换、删除

跨行内容查找、替换、删除

sed '/START-TAG/{:a;N;/END-TAG/!ba};/ID: 222/d' data.txt
/START-TAG/ {  # Match 'START-TAG'
:a             # Create label a
N              # Read next line into pattern space
/END-TAG/!     # If not matching 'END-TAG'...
           ba  # Then goto a
}              # End /{START-TAG/ block
/ID: 222/d     # If pattern space matched 'ID: 222' then delete it. 

 

清除范围START-TAG到END-TAG的内容

sed -i '/START-TAG/{:a;N;/END-TAG/!ba};//d' file.txt

替换范围START-TAG到END-TAG的内容为Target

sed -i '/START-TAG/{:a;N;/END-TAG/!ba};s/START-TAG.*END-TAG/Target/' file.txt

 

删除A到B之间的内容,跨行包括A,B

sed '/A/,/B/d' file.txt

 

<来源>

posted @ 2022-02-18 15:16  壹点灵异  阅读(362)  评论(0编辑  收藏  举报