sed - comment a matching line and x lines after it

后端 未结 3 1989
伪装坚强ぢ
伪装坚强ぢ 2021-02-02 01:02

I need help with using sed to comment a matching lines and 4 lines which follows it. in a text file.

my text file is like this:

[myprocess-a]
property1=1         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-02-02 01:12

    Using string concatenation and default action in awk.
    http://www.gnu.org/software/gawk/manual/html_node/Concatenation.html

    awk '/myprocess/{f=1} f>5{f=0} f{f++; $0="#" $0} 1'  foo.txt
    

    or if the block always ends with empty line

    awk '/myprocess/{f=1} !NF{f=0} f{$0="#" $0} 1'  foo.txt
    

提交回复
热议问题