使用 grep 和 xargs,避免“未终止的引号”; 错误

发布于 2024-07-19 03:26:35 字数 467 浏览 3 评论 0原文

我感到非常沮丧,我想是时候问一个问题了。

我正在尝试替换硬编码到 1000 个页面的网站上的电子邮件地址。 它位于 FreeBSD 6.3 服务器上。

这是我正在使用的命令:

grep -R --files-with-matches 'Email\@domain.com' 。 | 排序| 优衣库 | xargs perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/' *.html

这是我不断收到的错误:

xargs: untermerated quote

奇怪的是,当我运行该命令时3 个文件的测试用例(在嵌套结构中)它工作得很好。 我一直在谷歌搜索,大多数解决方案似乎都是在 . 和 xargs 之后的 -0。 然而,这会产生一系列不同的错误,使我相信我把东西放在了错误的地方。

在此先感谢您的帮助

I'm getting frustrated enough that I figured it was time to ask a question.

I'm trying to replace an email address across a website that is hard coded into 1000's of pages. It's on a FreeBSD 6.3 server.

Here is the command I am using:

grep -R --files-with-matches 'Email\@domain.com' . | sort | uniq | xargs perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/' *.html

And here is the error that I keep getting:

xargs: unterminated quote

Oddly enough, when I run that command on a test case of 3 files (in a nested structure) it works just fine. I've been googling and most solutions seem to deal with adding a -print0 after the . and a -0 after the xargs. However, this yields a different set of errors that lead me to believe I'm putting things in the wrong places.

thanks in advance for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

好菇凉咱不稀罕他 2024-07-26 03:26:35

帕克斯是正确的。 我将进一步将其更正为:

grep -R --files-with-matches 'Email\@domain.com' . -print0 | xargs -0 perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/'

编辑:

感谢 kcwu,这是完整的 FreeBSD:

grep -R --files-with-matches 'Email\@domain.com' . --null | xargs -0 perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/'

请注意,我已经删除了 sort 和 uniq。 --files-without-match 被记录为“在第一个匹配时停止”,因此您不会获得重复的文件。 -print0 和 -0 确保(并处理)一个以 null 结尾的文件列表,这至关重要,因为 POSIX 允许文件名包含换行符。

请注意,我不了解 perl,但我假设该部分大致相当于:

sed -i s/Email\@domain.com/Email\@newdomain.com/g

Pax is correct. I would further correct it to something like:

grep -R --files-with-matches 'Email\@domain.com' . -print0 | xargs -0 perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/'

EDIT:

Thanks to kcwu, this is the full FreeBSD:

grep -R --files-with-matches 'Email\@domain.com' . --null | xargs -0 perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/'

Note that I've removed sort and uniq. --files-without-match is documented to "stop on the first match" so you will not get duplicate files. -print0 and -0 ensure (and handle) a null-terminated file list, which is vital, because POSIX allows filenames to contain newlines.

Note that I don't know perl, but I'm assuming that part's roughly equivalent to:

sed -i s/Email\@domain.com/Email\@newdomain.com/g
转身泪倾城 2024-07-26 03:26:35

为什么要向 xargs 提供 HTML 文件列表? 该程序从管道(grep 的输出)获取其文件列表。

Why are you giving a list of HTML files to xargs? That program takes its file list from the pipeline (output of grep).

廻憶裏菂餘溫 2024-07-26 03:26:35

使用 GNU Parallel:

grep -R --files-with-matches 'Email\@domain.com' . | sort | uniq | parallel -q perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/g'

观看介绍视频以了解更多信息:http://www.youtube.com/watch ?v=OpaiGYxkSuQ

Use GNU Parallel:

grep -R --files-with-matches 'Email\@domain.com' . | sort | uniq | parallel -q perl -pi -e 's/Email\@domain.com/Email\@newdomain.com/g'

Watch the intro video to learn more: http://www.youtube.com/watch?v=OpaiGYxkSuQ

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文