Bash 已从文件B中删除文件A中的所有事件
我有两个文件:A和B A部分的内容:Bash 已从文件B中删除文件A中的所有事件,bash,sed,Bash,Sed,我有两个文件:A和B A部分的内容: http://example.com/1 http://example.com/2 http://example.com/3 http://example.com/4 http://example.com/5 http://example.com/6 http://example.com/7 http://example.com/8 http://example.com/9 http://example.com/4 文件B中的内容: http://exam
http://example.com/1
http://example.com/2
http://example.com/3
http://example.com/4
http://example.com/5
http://example.com/6
http://example.com/7
http://example.com/8
http://example.com/9
http://example.com/4
文件B中的内容:
http://example.com/1
http://example.com/3
http://example.com/9
http://example.com/4
现在,我想从文件A中删除文件B中出现的所有行
我尝试过以下方法:
for LINK in $(sort -u B);do sed -i -e 's/"$LINK"//g' A; echo "Removed $LINK";done
但是它没有做任何事情。
grep-vf
将更简单:
grep -vxFf file2 file1
http://example.com/2
http://example.com/5
http://example.com/6
http://example.com/7
http://example.com/8
您是否需要
-x
选项或确保http://example.com/1
从文件B中不删除http://example.com/100
etc?这里肯定需要@JonathanLeffler,-x
。使用sed
?允许您使用sed
编写sed
脚本吗?是否可以使用awk
?而且您得到的grep
解决方案比使用sed
或awk
更简单@JonathanLeffler不,它肯定不需要sed。