我有一个文件,正在逐行读取它。有些行中有美元符号,我想使用 sed 删除它们。例如,
echo $line
返回
{On the image of {$p$}-adic regulators},
另一方面,
echo $line | sed 's/\$//g'
正确返回
{On the image of {p}-adic regulators},
但是
title=`echo $line | sed 's/\$//g'`; echo $title
返回
{On the image of {$p$}-adic regulators},
最佳答案
在反引号中使用 sed 命令时,您需要转义反斜杠:
title=`echo $line | sed 's/\\$//g'` # note two backslashes before $
关于bash - 有没有一种方法可以通过 sed 从字符串中删除美元符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8823113/