Chinaunix

标题: shell提取多个字段 [打印本页]

作者: zzz2738    时间: 2014-06-19 11:54
标题: shell提取多个字段
本帖最后由 zzz2738 于 2014-06-19 12:12 编辑

写个shell想提取下面ip 和channel字段,awk  cut sed貌似无力,求助,谢谢啦。

123.242.249.101 - - [2014-06-19 09:49:18.934524] "GET /category/?channel=aui&language=zh-cn&output=json&sign=E2A78E847056893CB4BE9E949 HTTP/1.1" 200 8085 "-" "Quartett/Audi" 1114.0ms
194.20.244.84 - - [2014-06-19 00:00:04.862945] "GET /hfinfo/?adcode=130300&channel=auvi_telematics&enddate=2014-06-19&output=json&sign=F22EB3&startdate=2014-06-19 HTTP/1.1" 200 219 "-" "python-requests/2.1.0 CPython/2.7.5 Linux/2.6.32-358.el6.x86_64" 121.0ms
194.147.80.2 - - [2014-06-19 09:33:21.675554] "GET /realtime/station/?adcode=110000&channel=auvi&language=en&sign=F25F9150B HTTP/1.1" 200 8689 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" 4939.0ms

作者: Shell_HAT    时间: 2014-06-19 13:18
  1. sed 's/^\([^ ]\+\) .*channel=\([^&]\+\)&.*/\1 \2/' a.txt
复制代码

作者: zzz2738    时间: 2014-06-19 14:15
非常感谢!致敬:wink: 。回复 2# Shell_HAT


   




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2