Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 使用sed删除包含多个字符串的所有行_Regex_Bash_Unix_Awk_Sed - Fatal编程技术网

Regex 使用sed删除包含多个字符串的所有行

Regex 使用sed删除包含多个字符串的所有行,regex,bash,unix,awk,sed,Regex,Bash,Unix,Awk,Sed,我有两个文件。我想从log.txt中删除所有字符串(在url.txt中) sed -i '/$string/d' log.txt 第一个文件是url.txt google.com bing.com yahoo.com 第二个文件是log.txt 1.2.3 www.google.com bot 626.7.7 www.yahoo.com browser 35.5.6 www.test.com search 44.6.6 www.bing.com web 我想要这

我有两个文件。我想从log.txt中删除所有字符串(在url.txt中)

sed -i '/$string/d' log.txt
第一个文件是url.txt

google.com
bing.com
yahoo.com
第二个文件是log.txt

   1.2.3 www.google.com bot
   626.7.7 www.yahoo.com browser
   35.5.6 www.test.com  search
   44.6.6 www.bing.com  web
我想要这个输出:

35.5.6 www.test.com  search
此代码适用于字符串,但我希望从log.txt中删除所有字符串(在url.txt中)

sed -i '/$string/d' log.txt

您可以使用此
grep-v

grep -vwFf url.txt log.txt
35.5.6 www.test.com  search

以上内容仅与log.txt的特定所需字段中的特定URL匹配,扩展您的
sed
脚本,下面是扩展脚本,用于解析URL.txt中的每一行并删除log.txt中的相应编码字符串

while read string
do
    sed -i '/$string/d' log.txt
done < url.txt
读取字符串时
做
sed-i'/$string/d'log.txt
完成
如果存在,则会错误地删除较长的URL,例如,如果log.txt包含与bing.com相匹配的
44.6.6 www.thoughing.com网站
。您需要为grep添加
-w
参数。这仍然给你留下了一个问题,那就是它会错误地删除一行,比如
44.6.6 www.thoughing.com。很高兴这不是bing.com
,因为它在任何特定领域都不匹配,但这可能不是一个问题。理解你的观点,但这并不是说应该保留thoughing.com。他说“所有字符串”不限于根域。并且一个
bing.com.phising.to
被删除(可能是有希望的)(但是你保留了你的+1;-D)