[英]Delete a line in multiple files that contain a string in Linux
I am moving some of my pages from 8859
to UTF
so I just included the UTF
in my file that is included on most pages. 我将某些页面从
8859
移到了UTF
所以我只是将UTF
包含在大多数页面中包含的文件中。 I am trying to erase the line with the charset
definition from pages with that include. 我试图从包含该页面的页面上删除带有
charset
定义的行。
find . -type f -exec grep -lr 'headIncluded' {} + -exec sed -i '/meta http-equiv=\\"content-type\\" content=\\"text\\/html; charset/d' {} \\;
I thought this one should work, but I noticed that it erased the line in a few pages where headIncluded
was not present. 我以为这应该工作,但是我注意到它删除了几页不包含
headIncluded
的行。 Any suggestions to what is wrong with this command? 关于此命令有什么问题的任何建议?
为什么不尝试:
grep -lr "headIncluded" /pathtodirectory/* | xargs sed -i '/meta http-equiv=\"content-type\" content=\"text\/html; charset/d'
When you use +
to terminate the -exec
, the command is run with multiple files. 当使用
+
终止-exec
,该命令将与多个文件一起运行。 If any of those files contain the string, the grep will succeed. 如果这些文件中的任何一个包含字符串,则grep将成功。 Also, from the documentation "this variant of -exec always returns true", so the return value of
grep
is irrelevant. 另外,根据文档“ -exec的此变体始终返回true”,因此
grep
的返回值无关紧要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.