• shell获取某个时间段的nginx日志内容


    shell获取某个时间段的nginx日志内容

    小醉90s 2014-04-06 16:40:36 15297 收藏 1
    分类专栏: linux
    版权
    从nginx日志中获取2014:04:01日 21:30至21:50的日志内容

    # cat web.log

    192.168.16.105 - - [01/Apr/2014:21:26:21 +0800] "GET / HTTP/1.1" 502 172
    192.168.16.105 - - [01/Apr/2014:21:28:22 +0800] "GET / HTTP/1.1" 502 172 
    192.168.16.105 - - [01/Apr/2014:21:31:36 +0800] "GET / HTTP/1.1" 502 172 
    192.168.16.105 - - [01/Apr/2014:21:42:14 +0800] "GET / HTTP/1.1" 502 172  
    192.168.16.105 - - [01/Apr/2014:21:45:22 +0800] "GET / HTTP/1.1" 502 172 
    192.168.16.105 - - [01/Apr/2014:21:46:32 +0800] "GET / HTTP/1.1" 502 172 
    192.168.16.105 - - [01/Apr/2014:21:46:54 +0800] "GET / HTTP/1.1" 502 172 
    192.168.16.105 - - [01/Apr/2014:21:47:03 +0800] "GET / HTTP/1.1" 502 172  
    192.168.16.105 - - [01/Apr/2014:21:48:31 +0800] "GET / HTTP/1.1" 200 26 
    192.168.16.105 - - [01/Apr/2014:21:50:08 +0800] "GET / HTTP/1.1" 200 26  
    192.168.16.105 - - [01/Apr/2014:21:51:21 +0800] "GET / HTTP/1.1" 200 26    
    192.168.16.105 - - [01/Apr/2014:21:52:48 +0800] "GET / HTTP/1.1" 200 26 
    方法1:sed


    cat web.log | egrep "01/Apr/2014" | sed -n '/21:31:36/,/21:50:08/p'
    方法二:awk


    cat web.log | egrep "01/Apr/2014" | awk -F':' '$2 = 21 && $3 >= 30 && $3 <= 50'
    注意:

    1、sed中取的两个时间点21:31:36与21:50:08必须是日志中实际存在的,用21:30:01与21:50:01获取不到数据;
    2、awk中$3小于等于50,包含了50:01-50:59的日志数据;
    ————————————————
    版权声明:本文为CSDN博主「小醉90s」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/kelonsen/article/details/23033485

    改行去放羊
  • 相关阅读:
    我的Asp.Net Hello World程序

    快速排序
    Python是一门什么样的语言
    Python开发简介
    LVS(Linux Viretual Server) 负载均衡器 + 后端服务器
    易迷糊题
    python语言入门 第四天
    日常练习 1.0
    User_Login_Register_Shopping 1.0
  • 原文地址:https://www.cnblogs.com/musen/p/13351720.html
Copyright © 2020-2023  润新知