linux - Extract value from .gz log files in unix -
i'm trying extract specific value (e.g useragent in case) bunch of .gz log files compressed log files. format of each log statement in these log files looks :
2013-06-20;02:00:02.503 [664492205@qtp-446095113-8883]-activity [response@12293 appid=testapp useragent=bundledevicefamily/iphone,ipad (ipad; ipad2,5; ipad2,5; iphone os 6.1.3) exec_tm=123 flow=response tokn_tm=0 gw_tm=2314.529 http.status=200 id=029dde45-802c-462a-902b-138bc5490fba offeringid=ipad httpurl= test.com aud_tm=0 ipaddress=10.10.10.10 ]\ 2013-06-20;02:00:02.504 [664492205@qtp-446095113-8883]-activity [response@12293 appid=testapp useragent=fnetwork/609.1.4 darwin/13.0.0 id=029dde45-802c-462a-902b-138bc5490fba exec_tm=123 flow=response tokn_tm=0 gw_tm=2314.529 http.status=200 offeringid=ipad httpurl= test.com aud_tm=0 ipaddress=10.10.10.10 ]
in case, want extract useragent field , display result either in 1 of below formats:
useragent=bundledevicefamily/iphone,ipad (ipad; ipad2,5; ipad2,5; iphone os 6.1.3) useragent=fnetwork/609.1.4 darwin/13.0.0
and on..
or print values such :
bundledevicefamily/iphone,ipad (ipad; ipad2,5; ipad2,5; iphone os 6.1.3) fnetwork/609.1.4 darwin/13.0.0
edit : add more info, these space seperated fields such key1=value1 key2=value2 appear in order
appreciate help. thanks!
since mentioned key=value
pairs can appear in order, here 1 way of doing awk
.
zcat input.gz | awk -f= ' { for(i=1;i<=nf;i++) { if($i~/useragent/) { sub(/[^ ]+$/,"",$(i+1)) print "useragent="$(i+1) } } }'
Comments
Post a Comment