awk提取关键字数据


122.241.144.174 - - [31/Aug/2013:07:28:00 +0800] "GET /kid/books/study_5.html HTTP/1.1" 200 2458 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; KB974489)" - "_pk_cvar.1.42f8=%7B%7D; _pk_id.1.42f8=a163974504948716.1377904137.1.1377905212.1377904137.; _pk_ses.1.42f8=*; usercode=xxxxx;

由于日志没有规律所以不能直接提取,就可以用下面的办法:

提取日志里面usercode=后面的数据:

awk -F "usercode=" ’{print $2}’ usercode.txt |awk -F ";" ’{print $1}


Whatever is worth doing is worth doing well.