Grep log file greater than time stamp

前端 未结 2 1422
半阙折子戏
半阙折子戏 2021-01-04 11:04

I have a unix log file(application.log), that has logs with timestamp at the starting. I need to search for a pattern \"sent\" in this log file greater than time 2014-03-20

2条回答
  •  醉梦人生
    2021-01-04 11:43

    Try:

    sed -n '/^2014-03-20 14:05:54/,$ {/sent/p;}' file
    

    Note: This assumes that there is at least 1 line in your log file that actually starts with 2014-03-20 14:05:54 and that it's OK to include matches from that second in time.

    If the existence of such a line is not guaranteed, @shellter's awk approach is superior; to put it together:

    awk '$0 > "2014-03-20 14:05:54" && $0 ~ "sent"' file
    

提交回复
热议问题