在shell中, 使用sed进行替换的时候,因为替换命令本身就是在引号中的,所以书写的时候,就需要注意书写的格式,这里总结几种写法。最简单的是 echo "this is''' test\" string" | sed $'s/\'//g'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# shell中使用sed替换单引号 echo "this is''' test\" string" | sed $'s/\'//g' this is test" string # shell中使用sed替换双引号 echo "this is''' test\" string" | sed $'s/\"//g' this is''' test string # shell中使用sed替换双引号和单引号 echo "this is''' test\" string" | sed "s/[\'\"]//g" this is test string # shell中使用sed替换双引号和单引号 echo "this is''' test\" string" | sed "s/[\x27\x22]//g" this is test string # shell中使用sed替换双引号和单引号 echo "this is''' test\" string" | sed $'s/[\'\"]//g' this is test string |
0 Comments