Chinaunix

标题: aix sed 替换的值含有特殊字符 [打印本页]

作者: 路人呵呵    时间: 2013-11-04 14:48
标题: aix sed 替换的值含有特殊字符
本帖最后由 路人呵呵 于 2013-11-04 14:57 编辑

有一个文件 a.txt
内容是:
jl=x

---------------------
V_L=/u01/app/oracle
sed  '/jl/s/x/'${V_L}'/g' a.txt
提示
sed: Function /jl/s/x//u01/app/oracle/g cannot be parsed.
然后 sed  '/jl/s/x/'${V_L//\//\\\/}'/g' a.txt
ksh: "/jl/s/x/"${V_L//\//\\\/}"/g": 0403-011 The specified substitution is not valid for this command.
求指导 如何转义替换变量的 /
作者: zanyzhao    时间: 2013-11-04 14:51
s///改为s###试试
作者: Shell_HAT    时间: 2013-11-04 15:03
  1. V_L=/u01/app/oracle
  2. sed  "/jl/s#x#${V_L}#g" a.txt
复制代码

作者: 路人呵呵    时间: 2013-11-04 15:37
回复 3# Shell_HAT

可以替换
可以简单指点下 #的用途么。

   
作者: yestreenstars    时间: 2013-11-04 15:46
回复 4# 路人呵呵
s###等价于s///,除了#还可以用其他符号代替。
The syntax of the `s' (as in substitute) command is
`s/REGEXP/REPLACEMENT/FLAGS'.  The `/' characters may be uniformly
replaced by any other single character within any given `s' command.

The `/' character (or whatever other character is used in its stead)
can appear in the REGEXP or REPLACEMENT only if it is preceded by a `\'
character.

   




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2