linux - 如何从许多文件中删除包含特殊字符的字符串

标签 linux bash shell sed

我需要从目录和子目录中的所有文件中删除(替换为空白)一个字符串。

但是该字符串包含特殊字符,例如 &?.<>/ (这是一个网址)! 我尝试使用 sed 和 rpl 但没有成功:无法转义字符。 要更改的字符串的 ex

<script src='https://test.com?type=in2&frm=scr&'></script>

尝试使用

 rpl " <script src='https://test.com?type=in2&frm=scr&'></script>" "" index.php

我遇到了一个错误; NameError:名称“raw_input”未定义

我只需要知道如何在 sed 或 rpl 中转义这些 '/?.& 字符

最佳答案

it should DELETE the whole script line.

然后使用 grep-v

$ cat <<'EOF' >/tmp/test.txt
a
<script src='https://test.com?type=in2&frm=scr&'></script>
b
EOF
$ grep -x -v "<script src='https://test.com?type=in2&frm=scr&'></script>" /tmp/test.txt
a
b

关于linux - 如何从许多文件中删除包含特殊字符的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55259912/

相关文章:

linux - Bash编程快速搜索和提取方法

android - 如何在没有源码的情况下构建Android?

c++ - 如何在不使用 argv 和 argc 的情况下将总和值传递给 C++ 程序

bash - 如何从函数中有效地中止 Bash 脚本的执行

shell - Jenkins - 区 block "Execute shell"

java - 在 Maven 中,我如何发现依赖于特定依赖项的内容?

python - 如何在关机后 5 分钟重新启动树莓派?

bash - 无法使用 gsutil cp 上传到 Google Cloud Service,且没有任何可见错误,如何调试?

linux - 在文件夹中运行 "N"Shell 脚本

linux - 在 shell 脚本中比较字符串时出现 "Unexpected operator"错误