sed - comment a matching line and x lines after it

后端 未结 3 2024
伪装坚强ぢ
伪装坚强ぢ 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:09

    You can do this by applying a regular expression to a set of lines:

    sed -e '/myprocess/,+4 s/^/#/' 
    

    This matches lines with 'myprocess' and the 4 lines after them. For those 4 lines it then inserts a '#' at the beginning of the line.

    (I think this might be a GNU extension - it's not in any of the "sed one liner" cheatsheets I know)

提交回复
热议问题