读取access日志文件并解析url encode内容

#Shell脚本:读取access日志文件并解析url encode内容

抽取encode内容

$ head temp.txt
127.0.0.1 - - [22/Jul/2015:20:04:26 +0800] "GET /goods/search?keyword=%E9%BA%BB%E8%B1%86%E8%85%90 HTTP/1.1" 200 76 "-" "-"
127.0.0.1 - - [22/Jul/2015:20:04:30 +0800] "GET /goods/search?keyword=%E5%B0%8F%E7%B1%B3%E6%A4%92 HTTP/1.1" 200 1897 "-" "-"
127.0.0.1 - - [22/Jul/2015:20:04:39 +0800] "GET /goods/search?keyword=%E8%8F%8C%E7%B1%BB%E9%87%91%E9%92%88%E8%8F%87 HTTP/1.1" 200 1038 "-" "-"
127.0.0.1 - - [22/Jul/2015:20:04:49 +0800] "GET /goods/search?keyword=%E8%8C%84%E5%AD%90 HTTP/1.1" 200 1166 "-" "-"
127.0.0.1 - - [22/Jul/2015:20:04:51 +0800] "GET /goods/search?keyword=%E9%A6%99%E8%8F%9C HTTP/1.1" 200 429 "-" "-"

$ cat temp.txt | egrep -o '(%[A-Z0-9]{2})+' 
%E9%BA%BB%E8%B1%86%E8%85%90
%E5%B0%8F%E7%B1%B3%E6%A4%92
%E8%8F%8C%E7%B1%BB%E9%87%91%E9%92%88%E8%8F%87
%E8%8C%84%E5%AD%90
%E9%A6%99%E8%8F%9C

linux 命令行urldecode

$ alias urldecode='python -c "import sys, urllib as ul; print ul.unquote_plus(sys.stdin.read())"'
$ echo -n "%E7%99%BD%E8%90%9D%E5%8D%9C" | urldecode 
白萝卜

综合上述步骤:

$ cat temp.txt | egrep -o '(%[A-Z0-9]{2})+' | urldecode
麻豆腐
小米椒
菌类金针菇
茄子
香菜

补充:

按照出现次数降序排序并选择出现次数最多的10个

$ cat temp.txt | egrep -o '(%[A-Z0-9]{2})+' | urldecode  | sort | uniq -c | sort -t ' ' -k 2 -n -r | head -n 10
      1 麻豆腐
      1 香菜
      1 菌类金针菇
      1 茄子
      1 小米椒
      1


参考文档:

http://unix.stackexchange.com/questions/159253/decoding-url-encoding-percent-encoding


转载于:https://my.oschina.net/zhuguowei/blog/482490

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值