-2

The original logfile sample:

"GET /dynamic_preroll_playlist.fmil?domain=13nwuc&width=480&height=360&imu=medrect&pubchannel=filmannex&ad_unit=category_2&sdk_ver=2.4.1.3&embeddedIn=http%3A%2F%2Fwww.filmannex.com%2Fmovie%2Fend-of-the-tunnel%2F20872&sdk_url=http%3A%2F%2Fstatic2.filmannex.com%2Fflash%2F&viewport=10,261,971,0,981,10,10,261 HTTP/1.1", 200, 201, 1516, 16363, "http://static2.filmannex.com/flash/yume_ad_library.swf", pl.networks.com, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; FunWebProducts; GTB7.3; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30618; FunWebProducts; .NET4.0C)", "24_100_150_188_jZKFKQQjdRNM6e", "0rO0ABXd8AAAACgAAASQAAAaLAAAGiwAAASgAAAaLAAAGiwAAAVoAAAaLAAAGiwAAAVkAAAaKAAAGiwAAAdwAAAaKAAAGiwAAAhIAAAaKAAAGiwAAAhUAAAaKAAAGiwAAAhYAAAaKAAAGiwAAAhsAAAaKAAAGiwAAAiwAAAaKAAAGiw**", "-", "-", "@YD_1;233_2739", -, "-", "24.100.150.188", "199.127.205.6"

The required output is the 5rd and 6th field of viewport:

981 10

I got the gawk code below which yields the 3rd and 4th fields:

910 0

gawk 'match($0, /&viewport=[0-9]+,[0-9]+,([0-9]+),([0-9]+)/, m){print m[1], m[2]}' filename

Can anyone help me with this problem? Just a little change to the gawk command fetch the 5th and 6th parameters of viewport?

Any ideas? Thanks so much in advance :)

Servy
  • 202,030
  • 26
  • 332
  • 449
user1536782
  • 97
  • 1
  • 2
  • 12
  • Do a simple formatting to make your question readable. [Editing-tips](http://stackoverflow.com/editing-help) – mtk Aug 08 '12 at 00:22
  • @mtk - I see why he hasn't done that. He is highlighting the relevant part of his string using boldface, which can't be done within a block. – ghoti Aug 08 '12 at 00:39
  • @ghoti Still a formatting is possible. Have placed an edit in the queue, will hopefully appear soon. – mtk Aug 08 '12 at 00:43
  • Exact duplicate of: http://stackoverflow.com/questions/11855237/sed-using-in-logfiles – Steve Aug 08 '12 at 00:48
  • Why do you get 910 instead of 971 from the sample data? Surely, the extension from fields 3 & 4 to fields 5 & 6 is pretty much automatic? – Jonathan Leffler Aug 08 '12 at 01:32

2 Answers2

1

this command will do what you want:

awk '{split($0,a,"viewport=");split(a[2],b,",");print b[5],b[6]}' filename

gives:

981 10

If you do want the modified gawk command:

gawk 'match($0, /&viewport=[0-9]+,[0-9]+,([0-9]+),([0-9]+),([0-9]+),([0-9]+),([0-9]+)/, m){print m[3], m[4]}' filename

will also work.

I think the first solution is cleaner/clearer and also easier to modify.

Levon
  • 138,105
  • 33
  • 200
  • 191
0

This might work for you (GNU sed):

sed 's/.*&viewport=\(\([^,]*\),\([^,]*\),\)\{3\}.*/\2 \3/' file
potong
  • 55,640
  • 6
  • 51
  • 83