sed multiline delete with pattern

后端 未结 1 390
一整个雨季
一整个雨季 2020-11-30 11:45

I want to delete all multiline occurences of a pattern like

  {START-TAG
  foo bar
  ID: 111
  foo bar
  END-TAG}

  {START-TAG
  foo bar
  ID: 222
  foo bar         


        
相关标签:
1条回答
  • 2020-11-30 12:03

    You can use the following:

    sed '/{START-TAG/{:a;N;/END-TAG}/!ba};/ID: 222/d' data.txt
    

    Breakdown:

    /{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. 
    
    0 讨论(0)
提交回复
热议问题