LoginSignup
4
5

More than 3 years have passed since last update.

grepで特定日時のログを調べる

Last updated at Posted at 2019-06-19

はじめに

アクセスログやメールログを確認するときに、特定日時のログだけ取得したいことが案外あるので、メモ。

内容

6月18日 1時00分 ~ 1時15分 のログを調べたいとき

less hogehoge.txt | grep -E 'Jun 18 01:(0|1[0-5])'

【追記】

ある方からご指摘を受けawkでも表現してみました。

Example: 1日の0:00:00から2日の8:00:00まで取る時

cat /var/log/messages |awk -F - -v nowtime="Jul  2 08:00:00" -v agotime="Jul  1 0:00:00" 'agotime < $1 && $1 <= nowtime'

便利・・・。

参考

・特定の時刻のログをgrepを使って抽出したい
https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1450632084

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5