Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用grep获取Unix日志记录器日志_Unix_Grep - Fatal编程技术网

使用grep获取Unix日志记录器日志

使用grep获取Unix日志记录器日志,unix,grep,Unix,Grep,如何使用grep命令根据小时数获取日志?我想从20:00到23:00取日志 [1/10/16 23:55:33:018 PST] 00000057 ServerObj E SECJ0373E: Exception message at com.own.ws.wim.util.UniqueNameHelper.formatUniqueName(UniqueNameHelper.java:102) a

如何使用grep命令根据小时数获取日志?我想从20:00到23:00取日志

[1/10/16 23:55:33:018 PST] 00000057 ServerObj E   SECJ0373E: Exception message
          at                             com.own.ws.wim.util.UniqueNameHelper.formatUniqueName(UniqueNameHelper.java:102)
          at com.own.ws.wim.ProfileManager.getImpl(ProfileManager.java:1569)
请帮帮我,我是unix的初学者


谢谢。

这将获得显示日期20:00至22:59的日志

grep '^\[1/10/16 2[012]:'
工作原理

  • ^
    锚定到行首,因此仅在行首匹配
  • \[
    字面上匹配一个方括号。没有
    \
    方括号在regexp中是特殊的
  • [012]
    匹配数字0、1或2
这应该可以:

$ egrep '^\[[0-9/]+ 2[0-2]:' log_file

它工作正常。我想知道它是否可以获取1/10/16 17:00到1/11/16 5:30。它可以选择您建议的范围,但它将是一个带有交替
操作符的长regexp。可能更容易选择白天临时文件,然后重复grep以获得所需的时间范围。我不会使用grep来完成此任务,我会使用脚本使用诸如perl或python之类的语言