【发布时间】:2021-10-20 01:23:42
【问题描述】:
我需要用这个 HTML 递归查找所有文件:
<html id="blx-5fb3c619e82a2863d6567c52-000000001" class="blx-5fb3c619e82a2863d6567c52"><head>
<meta charset="utf-8">
<meta name="google" value="notranslate">
并用这个 HTML 替换它:
<html id="blx-5fb3c619e82a2863d6567c52-000000001" class="blx-5fb3c619e82a2863d6567c52"><head>
<meta charset="utf-8">
<meta name="google" value="notranslate">
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="date=no">
<meta name="format-detection" content="address=no">
<meta name="format-detection" content="email=no">
这是我将 grep 命令通过管道传输到 sed 的失败尝试:
grep --include="index.html" -PRwzl -e '<html id="blx-5fb3c619e82a2863d6567c52-000000001" class="blx-5fb3c619e82a2863d6567c52"><head>\n <meta charset="utf-8">\n <meta name="google" value="notranslate">\n' | xargs -i@ sed -i 's/<html id="blx-5fb3c619e82a2863d6567c52-000000001" class="blx-5fb3c619e82a2863d6567c52"><head>\n <meta charset="utf-8">\n <meta name="google" value="notranslate">\n/<html id="blx-5fb3c619e82a2863d6567c52-000000001" class="blx-5fb3c619e82a2863d6567c52"><head>\n <meta charset="utf-8">\n <meta name="google" value="notranslate">\n <meta name="google" value="notranslate">\n <meta name="format-detection" content="telephone=no">\n <meta name="format-detection" content="date=no">\n <meta name="format-detection" content="address=no">\n <meta name="format-detection" content="email=no">\n/g' @
单独的 grep 命令可以完美运行。
为清楚起见,这里将命令分成许多部分。:
grep --include="index.html" \
-PRwzl \
-e '<html id="blx-5fb3c619e82a2863d6567c52-000000001" class="blx-5fb3c619e82a2863d6567c52"><head>
\n <meta charset="utf-8">
\n <meta name="google" value="notranslate">
\n' \
| xargs -i@ sed -i 's/<html id="blx-5fb3c619e82a2863d6567c52-000000001" class="blx-5fb3c619e82a2863d6567c52"><head>
\n <meta charset="utf-8">
\n <meta name="google" value="notranslate">
\n
/<html id="blx-5fb3c619e82a2863d6567c52-000000001" class="blx-5fb3c619e82a2863d6567c52"><head>
\n <meta charset="utf-8">
\n <meta name="google" value="notranslate">
\n <meta name="google" value="notranslate">
\n <meta name="format-detection" content="telephone=no">
\n <meta name="format-detection" content="date=no">
\n <meta name="format-detection" content="address=no">
\n <meta name="format-detection" content="email=no">
\n
/g' @
【问题讨论】:
-
您的尝试是
grep命令,您声称该命令不成功但运行良好?澄清。 -
@Nic3500 我的尝试是将 grep 命令通过管道传送到 sed 命令。单独的 grep 命令可以正常工作。