[英]Using sed in shell script for replacing values in a file
Please help me creating a shell script to search all lines and replace format in a file using sed.请帮助我创建一个 shell 脚本来搜索所有行并使用 sed 替换文件中的格式。
Example - ['abc,xyz']
to be changed to ['abc','xyz']
示例 - ['abc,xyz']
更改为['abc','xyz']
Here you go:干得好:
[user@myserver ~]$ echo "['abc,xyz']" | sed "s:,:\',\':g"
['abc','xyz']
Here colon ( :
) is used as delimiter and backslash ( \\
) has been used as escape character in sed command.这里冒号 ( :
) 用作分隔符,反斜杠 ( \\
) 已用作 sed 命令中的转义字符。
这可能对你有用(GNU sed):
sed -E ':a;s/(\[('\''[^'\'',]*'\'',)*'\''[^'\'',]*),([^]]*'\''\])/\1'\'','\''\3/;ta' file
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.