Linux 使用sed指令插入到指定的行的上一行或者下一行

1.匹配到指定行,然后在上一行插入
   在/etc/config/wireless文件中匹配到'sta'字符串,然后在改行的上一行插入config wifi-iface 'ap' 
     sed -i "/'sta'/a\config wifi-iface 'ap'" /etc/config/wireless 
    说明:
       i:表示上一行
       a:表示下一行
 2.匹配到指定行,然后插入多行
    在/etc/config/wireless文件中匹配到'sta'字符串,然后在该行的下一行插入如下内容:
       config wifi-iface 'ap'   
             option device 'mt7628'
       sed -i "/'sta'/a\config wifi-iface 'ap' \n  option device 'mt7628'\n" /etc/config/wireless 

猜你喜欢

转载自blog.csdn.net/wgl307293845/article/details/98183932