简体   繁体   中英

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.

Example - ['abc,xyz'] to be changed to ['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.

这可能对你有用(GNU sed):

sed -E ':a;s/(\[('\''[^'\'',]*'\'',)*'\''[^'\'',]*),([^]]*'\''\])/\1'\'','\''\3/;ta' file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM