My file test.csv
contain Record `Ashish`
. I want to globally replace it with single quote 'Ashish'
.
I tried this command:
sed 's/`/'/g' test.csv
but it is not working. Please advise.
tr是替换字符的正确工具:
echo '`' | tr \` \'
Try using double quotes "
on the outside and escaping the backtic.
sed "s/\`/'/g" Test.in > Test.out
Also, if you want to change the original file, you have to use the -i
flag.
sed -i "s/\`/'/g" Test.in
你需要转义'
和`
字符:
sed s/\'/\`/g test.csv > out.csv
The reason that fails is because it is not possible to place a single quote in a single quoted string: https://www.gnu.org/software/bash/manual/bashref.html#Single-Quotes
The workaround is this:
sed 's/`/'"'"'/g'
's/`/'
) with a double-quoted string ( "'"
) and another single-quoted string ( '/g'
), or sed 's/`/'\\''/g'
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.