我在一个文件中有一个数据集,由三列(IP地址、端口、域名)组成,如下所示:
172.56.146.16 61981 r5---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.13 64576 r2---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.46 56483 ssl.gstatic.com
172.56.146.14 57054 r3---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.14 58157 r3---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.18 62666 ssl.gstatic.com
172.56.146.15 55682 r4---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.16 52234 r5---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.59 57106 ssl.gstatic.com
172.56.146.18 58897 ssl.gstatic.com
172.56.146.16 52258 r5---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.15 55694 r4---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.32 64281 ssl.gstatic.com
172.56.146.39 60581 ssl.gstatic.com
172.56.146.13 57137 r2---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.14 64763 r3---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.13 57135 r2---sn-uhvcpax0n5-x5ue.googlevideo.com
172.56.146.15 51318 r4---sn-uhvcpax0n5-x5ue.googlevideo.com
我还在文件中设置了一个密钥,只包含IP地址和端口:
172.56.146.15 49333
172.56.146.16 52233
172.56.146.46 56483
172.56.146.14 58928
172.56.146.16 61981
172.56.146.13 64576
172.56.146.14 58157
172.56.146.18 62666
172.56.146.15 55682
172.56.146.14 57054
现在我想逐个考虑密钥集中的所有行,将其作为数据集的输入,作为回报,我应该能够从数据集中获取每个密钥的域名(从密钥集中获取的IP地址和端口)。你知道吗
例如,对于172.56.146.15 49333
,我可以得到结果“domain not found”,对于172.56.146.46 56483
,我应该得到结果ssl.gstatic.com
,依此类推。有人能告诉我如何使用shell命令或脚本来实现这一点吗?结果输出如下(与键集中的键一一对应):
domain not found
ssl.gstatic.com
r5---sn-uhvcpax0n5-x5ue.googlevideo.com
使用GNU bash:
输出:
用这个
跑步:
结果:
两种解决方案,都是将数据文件读入数组,然后查找密钥文件中每行的数组值。你知道吗
“纯”Bash(仅内置):
这称为:
其中,
SO.sh
是脚本文件的名称,data
是数据文件,keys
是带有键的文件。Awk公司:
假设它存储在
SO.awk
中,则调用它,如下所示:对于大文件,awk解决方案的速度将提高几个数量级。你知道吗
相关问题 更多 >
编程相关推荐