[root@zgc ~]# cat test
disable yes
+++++
[root@zgc ~]#
执行如下命令替换:
sed -i 's/disable\(\s\+\)yes/disable\1no/g' test
说明:
\(..\) 保存匹配的空字符
\1 代表括号内保存的匹配
替换后结果如下,保持了字符间的空字符不变:
[root@zgc ~]# cat test
disable no
+++++
sed中+号,代表本身,标识一个或多个需要转义:
[root@zgc ~]# sed -i 's/+/*/g' test
[root@zgc ~]# cat test
disable no
*****