sed Address and address range Negating address range


Example

$ cat ip.txt 
address
range
substitution
1234
search pattern
sample
Add Sub Mul Div
  • Deleting lines other than address specified

    $ sed '/[0-9]/!d' ip.txt 
    1234
     
    $ sed -n '/[0-9]/p' ip.txt 
    1234
      
    $ sed '$!d' ip.txt 
    Add Sub Mul Div
      
    $ sed -n '$p' ip.txt 
    Add Sub Mul Div
    
  • Search and replace on lines not matching a pattern

    $ sed '/ /! s/^/#/' ip.txt 
    #address
    #range
    #substitution
    #1234
    search pattern
    #sample
    Add Sub Mul Div
    
    $ sed '/add/,/sub/! s/[aeiou]//gi' ip.txt 
    address
    range
    substitution
    1234
    srch pttrn
    smpl
    dd Sb Ml Dv