SED delete lines between two pattern matches

后端 未结 5 1670
花落未央
花落未央 2020-12-12 02:12

I am trying to replace lines between two pattern/string matches using SED see below. I need to delete lines below interface GigabitEthernet0/3 up to inter

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 03:04

    This might work for you:

    sed -e '\#^interface GigabitEthernet0/3#,/^!/{//!d}' input_file
    

    or as you described it in the question:

    sed -e '\#^interface GigabitEthernet0/3#,\#^interface GigabitEthernet0/4#{//!d;/4/s/^/!\n/}' input_file
    

    presuming you want to preserve the ! on the line prior to the second interface. If you don't want the ! then omit /4/s/^/!\n/ from the last bit of the sed command

提交回复
热议问题