remove block of text between two lines based on content

前端 未结 3 1096
慢半拍i
慢半拍i 2020-12-20 05:01

I need to remove/filter a very large log file i managed to bring the log-file into blocks of text starting with a line containing <-- or -->

3条回答
  •  无人及你
    2020-12-20 05:37

    This might work for you (GNU sed);

    sed '/<--\|-->/!b;:a;/Content-Length/!{$!{N;ba}};//{/REGISTER/d}' file
    
    • /<--\|-->/!b if a line does not contain <-- or --> print it
    • :a;/Content-Length/!{$!{N;ba}} keep appending lines until the string Content-Length or the end of file is encountered.
    • //{/REGISTER/d} if the line(s) read in contains Content-Length and REGISTER delete it/them else print it/them as normal.

提交回复
热议问题