bash - 有没有一种方法可以通过 sed 从字符串中删除美元符号?

标签 bash sed

我有一个文件,正在逐行读取它。有些行中有美元符号,我想使用 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/

相关文章:

perl - 将 2 行合并为 1

python - 如何根据索引替换子字符串?

Bash:不是绝对的脚本#!解释器?

bash - 使用具有多个参数的 AWK 比较 2 个文件

sed - 如何使用 sed 取消注释第二个模式匹配上的多行?

Linux 查找与 sed 不工作

python - 如何从 Unicode 文件中删除字母数字单词

linux - 如何修复 bash az 命令未找到

PHP JSON 函数在被称为 CLI 脚本时不可用?

linux - 执行脚本的多个实例 - GNU Parallel