从单词列表中删除包含单词的行

如何从列表中删除包含数字的行? bash或任何其他脚本语言或excel或应用程序。

这是我的例子:

COLUMN A COLUMN B ____________________________________________ 192.168.1.1:27794 27800 192.168.1.1:27795 27799 192.168.1.1:27796 27794 192.168.1.1:27797 27795 192.168.1.1:27798 192.168.1.1:27799 192.168.1.1:27800 192.168.1.1:27801 

列A和列B是分开的文件。

列A full.txt列B todelfromfull.txt

所以如果列A中的行包含列BI中的单词,那么希望A列中的行被删除,而列B中的行

我用bash尝试了sed但没有成功

非常感谢

使用awk

 awk -F : 'NR==FNR{a[$1];next} !($2 in a) ' todelfromfull.txt full.txt 

说明

  • -F :字段拆分:
  • NR==FNR{a[$1];next}读取第一个文件todelfromfull.txt ,将端口保存在关联数组a
  • !($2 in a)如果第2列不在数组a中,则!($2 in a)打印出来。

使用GNU grep:

 fgrep -vw -f todelfromfull.txt full.txt 

你也可以使用Bash:

 file=$(< todelfromfull.txt) while IFS=: read ip port; do n=0 for i in $file; do if [[ $i == $port ]]; then ((n++)) break fi done if [ $n -eq 0 ]; then echo $ip $port fi done < full.txt