Bash 用于比较两个文件并显示保存在另一个文件中的重复项计数的脚本包括 ip?

Bash script to compare two files and display the count of duplicates saved in another file include ip?

我想比较文件 1 和文件 2 使用它们的第一列和四列整行或文件 2 中它们在文件 1 中匹配的行。我还想将结果保存在第三个文件,并计算重复项。

文件 1:

00:00:00 W1 T Y8.4.237 51934 X1.69 51934 17.203.73.207 #S  
00:00:00 W1 U Y8.1.161 63675 W121 63675 200.47.95.8 10]  
00:00:00 W1 T Y8.42.69 35684 X1.71 35684 2.250.5.106 #S  
00:00:00 Q2 T Y0.244.246 61631 X4.126 61631 3.211.0.248 #S  
00:00:01 W1 U Y8.1.161 63674 W121 63674 200.47.95.18 22]  

文件 2:

Y8.4.237  
Y8.1.161  
Y8.42.69   
Y0.244.246   
Y8.1.161

在 file3 中,我想包含重复项并计算它们。

例如结果为:

Y8.4.237 :  Total 0
Y8.1.161:   Total 2 
Y8.42.69:   Total 0
Y0.244.246 :Total 0

我使用了这个命令,但我无法通过动态更改?

awk '{print }'  file1.txt |grep  -w -c "Y8.1.161"  

我该怎么做?非常感谢您的帮助和努力

根据 file1.txt 的内容创建一个关联数组。然后在读取 file2.txt.

时增加计数
awk 'FNR==NR { c[] = 0; next; } # file2.txt
      in c { c[]++ } # file1.txt
     END { for (x in c) printf("%s: Total %d\n", x, c[x]) }
' file2.txt file1.txt > result.txt