用于组合行并总结它们的 awk 命令
这是我的格式。
Source IP Destination IP Received Sent
192.168.0.1 10.10.10.1 3412 341
192.168.0.1 10.10.10.1 341 43
192.168.0.1 10.22.22.2 34 334
192.168.0.1 192.168.9.3 34 243
但这些文件非常大。我基本上想给出每个源IP的总带宽。因此,我需要组合所有 uniq 源 IP,然后添加所有唯一的接收列,然后添加发送列。最终结果将是:
源 ip - 接收到的数据包总数 - 发送的数据包总数
也可以对源和目标 IP 进行 uniq,这样我也可以获得
源 ip - 目标 ip - 接收到的数据包总数 - 发送的数据包总数
任何帮助将不胜感激
This is the format that I have.
Source IP Destination IP Received Sent
192.168.0.1 10.10.10.1 3412 341
192.168.0.1 10.10.10.1 341 43
192.168.0.1 10.22.22.2 34 334
192.168.0.1 192.168.9.3 34 243
But a very large file of these. I basically want to give the total bandwidth of each source IP. So I need to combine all uniq source IPs and then add the received columns of everything that is unique and then add the sent columns. The end outcome would be:
source ip - total received packets - total sent packets
It would also be nice to uniq the source and destination IP as well so I could also get
source ip - destination ip - total received packets - total sent packets
Any help would be greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需查看源 IP:
对于源/目标对,只需稍加修改:
just looking at the Source IP:
for source/destination pairs, just a slight modification:
Ruby(1.9+)
测试运行:
Ruby(1.9+)
test run:
我会做一个(有点格式化,但你可以把它写在一行中):
I would do a (a little bit formatted but you could write it in one line):
InputFile 被读取两次,因此在最后添加了两次。
第一次出现的输入文件(用于 if(NR==FNR) 条件)是构建两个数组,第二个输入文件(用于 else 条件)是打印所有组合并将数组值设置为空白,这样我们就不会再次打印。
下面格伦的解决方案要优越得多,它只读取文件一次
InputFile is read twice hence it is added two times at the end.
The first occurence of inputfile (which is used in if(NR==FNR) condition) is to build the two arrays and second inputfile (used in else condition) is to print all the combinations and also setting the array value to blank so that we wont print again.
Glenn's Solution below is much superior it reads the file only once