否定地址范围

$ cat ip.txt 
address
range
substitution
1234
search pattern
sample
Add Sub Mul Div
  • 删除指定地址以外的行

    $ 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
    
  • 搜索和替换与模式不匹配的行

    $ 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