基于唯一列合并两个列表文件 [英] Merging two lists files based on unique column

查看:77
本文介绍了基于唯一列合并两个列表文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文件,一个名为3列的NATLog,另一个是2列的Sourceports,下面是NATLog文件的示例.

I have two files, one is named NATLog with 3 columns and the other is Sourceports with 2 columns, Below is a sample of the NATLog file.

14 172.18.2.12 445 
50 172.18.24.4 123
80 10.2.123.37 22
68 172.18.1.37 25

我想将NATLog文件的最后一列与Sourceports文件的第一列匹配,并将关联的服务作为第四列附加到NATLog文件中

I want to match the last column of the NATLog file with the First Column of the Sourceports file and append the associated service to the NATLog file as a 4th column

445 SMB
123 Network Time Protocol (NTP)
22  SSH
25  SMTP(Insecure)

所需的输出

14 172.18.2.12 445 SMB 
50 172.18.24.4 123 Network Time Protocol (NTP)
80 10.2.123.37 22  SSH
68 172.18.1.37 25  SMTP(Insecure)

我正在尝试学习AWK来完成此任务,但是我需要一些帮助,请您能帮助我,谢谢

I am trying to learn AWK to accomplish this, but I am in need of some help, could you please assist me, thanks

推荐答案

尝试awk,

$ awk ' NR==FNR {x=$1; $1="";a[x]=$0; next } { print $0, a[$3] } ' Sourceports NATLog
14 172.18.2.12 445   SMB
50 172.18.24.4 123  Network Time Protocol (NTP)
80 10.2.123.37 22  SSH
68 172.18.1.37 25  SMTP(Insecure)

$

这篇关于基于唯一列合并两个列表文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆