日期:2014-05-16 浏览次数:20761 次
- 113.133.123.123 2012-02-10 14:00:03 "GET http://stat.abc.com:3128/aop?a=123&b=23&c=24d=200|ab122|a12|sd1223d|324&e=2321" - 219.114.114.123 2012-02-10 14:00:03 "GET http://stat.abc.com:3128/aop?a=123&b=23&c=24d=200|ab12|2|asd|324&e=2321" 119.41.13.17 113.31.123.123 2012-02-10 14:00:03 "GET http://stat.abc.com:3128/aop?a=123&b=23&c=24d=200|ab|122|asd|324&e=2321" - 211.139.21.197 2012-02-10 14:00:03 "GET http://stat.abc.com:3128/aop?a=123&b=23&c=24d=200|ab1|22|2d|324&e=2321" - 112.65.123.232 2012-02-10 14:00:03 "GET http://stat.abc.com:3128/aop?a=123&b=23&c=24d=200|a222|asd|324&e=2321" 221.21.11.121 113.31.1.27 2012-02-10 14:00:03 "GET http://stat.abc.com:3128/aop?a=123&b=23&c=24d=200|ab|asd|324&e=2321"
- 113.133.123.123 2012-02-10 14:00:03 "GET http://stat.abc.com:3128/aop?a=123&b=23&c=24d=200|ab122|asd|324&e=2321"
$ sed -r -n '/^-.*$/s/^.*(([0-9]{3}(\.|\b)){4}).*a\=([0-9]+)\&b\=([0-9]{2})\&c\=([0-9]+)d\=([0-9]+)\|(.*)\|([0-9]{3}).*$/\1 \2 \3 \5 \6 \7 \8 \9/p' file 113.133.123.123 123 23 24 200 ab122|a12|sd1223d 324 219.114.114.123 123 23 24 200 ab12|2|asd 324
------解决方案--------------------
一个awk脚本,一堆sub搞定
# cat ./parse.awk #!/usr/bin/awk -f BEGIN { FS=" |=" } { ip=$1 if (ip == "-") ip = $2 gsub(/[^0-9]/, "", $5) gsub(/[^0-9]/, "", $6) gsub(/[^0-9]/, "", $7) gsub(/[^0-9]/, "", $9) n=split($8, d, "|") gsub(/[^0-9]/, "", d[n]) sub(/[0-9]*\|/, "", $8) sub(/\|[0-9]*&e$/, "", $8) print ip,$5,$6,$7,d[1],$8,d[n],$9 }