删除多个文件中包含 Linux 中字符串的一行
Delete a line in multiple files that contain a string in Linux
我正在将我的一些页面从 8859
移动到 UTF
,所以我只是将 UTF
添加到我的文件中,大多数页面都包含该文件。我试图从包含该内容的页面中删除带有 charset
定义的行。
find . -type f -exec grep -lr 'headIncluded' {} + -exec sed -i '/meta http-equiv=\"content-type\" content=\"text\/html; charset/d' {} \;
我认为这个应该可以,但我注意到它删除了几页中 headIncluded
不存在的行。对这个命令有什么问题有什么建议吗?
为什么不试试:
grep -lr "headIncluded" /pathtodirectory/* | xargs sed -i '/meta http-equiv=\"content-type\" content=\"text\/html; charset/d'
当你用+
终止-exec
时,命令是运行多文件。如果这些文件中的任何一个包含该字符串,则 grep 将成功。此外,根据文档 "this variant of -exec always returns true",因此 grep
的 return 值无关紧要。
我正在将我的一些页面从 8859
移动到 UTF
,所以我只是将 UTF
添加到我的文件中,大多数页面都包含该文件。我试图从包含该内容的页面中删除带有 charset
定义的行。
find . -type f -exec grep -lr 'headIncluded' {} + -exec sed -i '/meta http-equiv=\"content-type\" content=\"text\/html; charset/d' {} \;
我认为这个应该可以,但我注意到它删除了几页中 headIncluded
不存在的行。对这个命令有什么问题有什么建议吗?
为什么不试试:
grep -lr "headIncluded" /pathtodirectory/* | xargs sed -i '/meta http-equiv=\"content-type\" content=\"text\/html; charset/d'
当你用+
终止-exec
时,命令是运行多文件。如果这些文件中的任何一个包含该字符串,则 grep 将成功。此外,根据文档 "this variant of -exec always returns true",因此 grep
的 return 值无关紧要。