字符串 a/b/c/def
比如要替换字符串 a/b/c 为aaa
# 未加转义符
[root@localhost ~]# sed -i 's/a/b/c/aaa/g' test.txt sed: -e expression #1, char 7: unknown option to `s'
不加转义则报错
# 加转义
[root@localhost ~]# sed -i 's/a\/b\/c/aaa/g' test.txt [root@localhost ~]# cat test.txt aaa/def
# 加转义符不美观,可以换个分隔符来实现
[root@localhost ~]# cat test.txt a/b/c/def [root@localhost ~]# sed -i 's#a/b/c#aaa#g' test.txt [root@localhost ~]# cat test.txt aaa/def
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/4807.html