码迷,mamicode.com
首页 > 其他好文 > 详细

获取日志$6到$NF的字段

时间:2015-06-19 21:45:03      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:awk


如何获取日志从$6到$NF的字段

aa文件:


Jun 19 16:40:19 192_168_101_38 snmpd[20032]: Connection from UDP: [192.168.100.3]:42043->[192.168.101.38] a b c
Jun 19 16:40:19 192_168_101_38 snmpd[20032]: Connection from UDP: [192.168.100.3]:43241->[192.168.101.38] asdfasdf
Jun 19 16:40:19 192_168_101_38 snmpd[20032]: Connection from UDP: [192.168.100.3]:59912->[192.168.101.38] 1 2 2
Jun 19 16:40:19 192_168_101_38 snmpd[20032]: Connection from UDP: [192.168.100.3]:54701->[192.168.101.38]asdfas aaaa
Jun 19 16:40:19 192_168_101_38 snmpd[20032]: Connection from UDP: [192.168.100.3]:59112->[192.168.101.38]asdf adfsaf adfsdd
Jun 19 16:40:19 192_168_101_38 snmpd[20032]: Connection from UDP: [192.168.100.3]:44452->[192.168.101.38]
Jun 19 16:40:19 192_168_101_38 snmpd[20032]: Connection from UDP: [192.168.100.3]:37467->[192.168.101.38]
Jun 19 16:40:19 192_168_101_38 snmpd[20032]: Connection from UDP: [192.168.100.3]:49426->[192.168.101.38]
Jun 19 16:40:19 192_168_101_38 snmpd[20032]: Connection from UDP: [192.168.100.3]:58209->[192.168.101.38]
Jun 19 16:40:19 192_168_101_38 snmpd[20032]: Connection from UDP: [192.168.100.3]:39767->[192.168.101.38]


方法一如下:

awk   ‘{for(i=6;i<=NF;i++) printf " "$i;if (NF > 6) printf "\n";}‘ aa


方法二如下;

awk ‘{a=index($0,$6);print substr($0,a)}‘ aa

本文出自 “秋天的童话” 博客,请务必保留此出处http://wushank.blog.51cto.com/3489095/1663656

获取日志$6到$NF的字段

标签:awk

原文地址:http://wushank.blog.51cto.com/3489095/1663656

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!