【发布时间】:2020-01-07 02:41:34
【问题描述】:
有2个文件,file1是telnet命令的输出,即
25-08-2019 : Port port1 of URL http://ip1:port1/ is [ NOT OPEN ]
25-08-2019 : Port port2 of URL http://ip2:port2/ is [ NOT OPEN ]
还有一个是file2,就像
http://ip1:port1/, ZOOM1
http://ip2:port2/, ZOOM2
http://ip3:port3/, ZOOM3
我需要根据公共 IP 和端口合并这两个文件。输出应该是第三个文件,如:
25-08-2019 : Port port1 of URL http://ip1:port1/ is [ NOT OPEN ] ZOOM1
25-08-2019 : Port port2 of URL http://ip2:port2/ is [ NOT OPEN ] ZOOM2
我尝试了join,但join 在我的shell 中给出了错误。 没有join 的任何帮助都会非常有帮助。
我尝试了join,它作为命令行工作,但在bash 和sh 中都失败了。而且它不匹配,它只是复制粘贴。
paste -d " : " file1 <(cut -s -d ',' -f2 file2)
我也尝试了awk 命令,但它没有按预期处理文件。
awk 'NR==FNR {h[$2] = $3; next} {print $1,$2,$3,h[$2]}' file2 file1 > file3
【问题讨论】:
-
我尝试加入,但加入在我的 shell 中出现错误 - 你是如何尝试的?
-
您的
awk尝试正确:awk 'NR==FNR {h[gensub(",","",1,$1)] = $2; next} {print $0,h[$7]}' file2 file1