grep 和 awk 解析行
我有一条看起来像这样的行:
Feb 21 1:05:14 host kernel: [112.33000] SRC=192.168.0.1 DST=90.90.90.90 PREC=0x40 TTL=51 ....
I would like to the list of uniq IPs from SRC=
我怎样才能做到这一点?谢谢
I have e a line that looks like:
Feb 21 1:05:14 host kernel: [112.33000] SRC=192.168.0.1 DST=90.90.90.90 PREC=0x40 TTL=51 ....
I would like to the a list of uniq IPs from SRC=
How can I do this? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这将起作用,尽管如果您愿意,您可以在单个 awk 脚本中进一步简化它:
This will work, although you could probably simplify it further in a single awk script if you wanted:
grep -o 'SRC=\([^]\+\)' |切-d=-f2|排序-u
grep -o 'SRC=\([^ ]\+\)' | cut -d= -f2 | sort -u
这将按顺序打印 IP 地址,不带“SRC=”字符串:
示例输出:
This will print the IP addresses in order without the "SRC=" string:
Example output:
这个 awk 脚本将执行以下操作:
This awk script will do:
红宝石(1.9+)
Ruby(1.9+)