gpt4 book ai didi

linux - Bash,Linux,需要根据另一个文件的匹配内容从一个文件中删除行

转载 作者:太空宇宙 更新时间:2023-11-04 09:05:40 25 4
gpt4 key购买 nike

有许多示例说明当同一行存在于另一个文件中时如何删除该文件中的行。我已经通读了它们,如果整行匹配,它们都会被删除。示例如下:grep -vxF -f file1 file2

我的略有不同。我有一个来 self 的网站和我的客户网站的 URL 列表。当域与另一个文件中的域匹配时,我想从该文件中删除行。

所以第一个文件可能是这样的:

http://www.site1.com/some/path
http://www.site2.com/some/path
http://www.site3.com/some/path
http://www.site4.com/some/path

第二个文件可以是:

site2.com
www.site4.com

我希望输出为:

http://www.site1.com/some/path
http://www.site3.com/some/path

最佳答案

你有太多的 grep 标记。具体来说:-x 将使您无法获得所需的结果。

假设 file1 有模式,file2 有 URL,只需使用:

grep -v -f file1 file2

-x 标志将阻止您获得想要的结果:使用 -x 意味着:只匹配整行,即只匹配一行如果该行是准确的,例如site2.com

来自 man grep:

-x, --line-regexp

Select only those matches that exactly match the whole line.

关于linux - Bash,Linux,需要根据另一个文件的匹配内容从一个文件中删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12011126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com