【问题标题】:How to grep the file with time range [closed]如何grep具有时间范围的文件[关闭]
【发布时间】:2019-08-21 20:30:10
【问题描述】:

我有日志文件,需要在 10 到 11 之间使用 Connection Refused 行 grep 文件

文件

2018-07-11 10:12:06,288 - Admin logged in
2018-07-11 10:15:06,288 - User logged in Connection Refused
2018-07-11 10:16:06,288 - Admin logged in
2018-07-11 10:18:06,288 - User logged in Connection Refused
2018-07-11 11:19:06,288 - User logged in Connection Refused

想要的结果

2018-07-11 10:15:06,288 - User logged in Connection Refused
2018-07-11 10:18:06,288 - User logged in Connection Refused

命令

grep - i "Connection Refused" file

【问题讨论】:

  • 发布你的命令
  • grep - i "Connection Refused" file || grep '2018-07-11 10'
  • 代码应该在你的 Q 正文中,而不是作为评论(请)。尝试将|| 更改为仅一个|。 (|| 是 shell 的逻辑或)。祝你好运。

标签: bash grep


【解决方案1】:

使用下面的命令

grep  -i "Connection Refused" file | grep "2018-07-11 10"

【讨论】:

    【解决方案2】:
    grep  -i "Connection Refused" yourlogfile | grep "2018-07-11 10"
    

    【讨论】:

      【解决方案3】:
      awk '$0>="2018-07-11 10" && $0<="2018-07-11 11" && /Connection Refused/' file
      

      输出:

      2018-07-11 10:15:06,288 - 用户登录连接被拒绝 2018-07-11 10:18:06,288 - 用户登录连接被拒绝

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-26
        • 1970-01-01
        • 1970-01-01
        • 2012-10-07
        相关资源
        最近更新 更多