标签: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
标签:awk
原文地址:http://wushank.blog.51cto.com/3489095/1663656