shell中,使用sed 替换单引号和双引号的几种写法

作者

在shell中, 使用sed进行替换的时候,因为替换命令本身就是在引号中的,所以书写的时候,就需要注意书写的格式,这里总结几种写法。简单的是 echo "this is''' test\" string" | sed $'s/\'//g'

# 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

一条评论

回复

您的电子邮箱地址不会被公开。