Chinaunix

标题: awk中[和]作为FS [打印本页]

作者: jackhuntcn    时间: 2014-04-04 15:18
标题: awk中[和]作为FS
比如文本如下:
  1. 66.249.64.6 - - [03/Apr/2014:22:14:44 -0400] "GET /index.php/feed/2014/04/ HTTP/1.1" 200 18755 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
复制代码
需要获取 [03/Apr/2014:22:14:44 -0400] 这段文本
想通过awk指定 [ 或 ] 作为FS,打印$2的方式,请问该怎么做?

试过这种不行
awk -F"[\[\]]" '{print $2}' file

作者: jackhuntcn    时间: 2014-04-04 15:21
  1. # tail -1 access.log | awk -F'[][]' '{print $2}'      
  2. 03/Apr/2014:22:14:44 -0400
复制代码
晕,这样居然可以。。
作者: jeffreyst    时间: 2014-04-04 15:45
学习中~~
作者: 关阴月飞    时间: 2014-04-04 16:02
回复 2# jackhuntcn


    牛,学习了!!!




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