使用日志文件桑达 [英] Sed using in logfiles
问题描述
原来的日志文件示例:
GET /dynamic_$p$proll_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,971,0,10,261 HTTP / 1.1,200,201,1516,16363, http://static2.filmannex.com /flash/yume_ad_library.swf ,pl.networks.com,Mozilla的/ 4.0(兼容; 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
"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,971,0,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"
所需的输出是第三和视口的第4个领域:
The required output is the 3rd and 4th field of viewport:
971 0
我使用的命令:
sed -n 's/.*viewport=\([^&]*\)/\1 /p' filename
得到错误的输出: 10,261,971,0,971,0,10,261 ** HTTP / 1.1,200,201,1516,16363,...
太多以下是冗余信息。
谁能帮我解决这个问题?使用sed命令获取视口的第3和第4个参数?
Can anyone help me with this problem? Use the sed command fetch the 3rd and 4th parameter of viewport?
非常感谢提前:)
推荐答案
只需使用AWK
gawk 'match($0, /&viewport=[0-9]+,[0-9]+,([0-9]+),([0-9]+)/, m){print m[1], m[2]}'
请注意:第三个参数匹配
仅在 GAWK
是可用的,所以这个脚本是呆子特定的。
说明:我们提供的正则表达式匹配
的功能,它可以捕获在视
第三和第四场。 匹配
如果提供的正则表达式可以针对整个记录的一些子被成功匹配返回非零值。
然后,它只是打印捕获组。
Note: Third argument to match
is available only in gawk
, so this script is gawk-specific.
Explanation: we provide regex to match
function, which captures third and fourth field in viewport
. match
returns non-zero value if provided regex can be successfully matched against some substring of whole record.
Then it just prints captured groups.
这篇关于使用日志文件桑达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!