alvas
alvas

Reputation: 122042

How to grep lines with date formats?

I have a log file that is created from a bash script that uses $(date), so there are dates in such a format:

Fri Apr 24 22:10:39 CEST 2015

The log file looks like this:

Using SCRIPTS_ROOTDIR: /home/gillin/moses/scripts
Using multi-thread GIZA
using gzip 
(1) preparing corpus @ Fri Apr 24 22:10:39 CEST 2015
Executing: mkdir -p /media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus
(1.0) selecting factors @ Fri Apr 24 22:10:39 CEST 2015
Forking...
(1.2) creating vcb file /media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus/en.vcb @ Fri Apr 24 22:10:39 CEST 2015
(1.1) running mkcls  @ Fri Apr 24 22:10:39 CEST 2015
/home/gillin/moses/training-tools/mkcls -c50 -n2 -p/media/2tb/ccexp/corpus.exp/train-clean.en -V/media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus/en.vcb.classes opt
Executing: /home/gillin/moses/training-tools/mkcls -c50 -n2 -p/media/2tb/ccexp/corpus.exp/train-clean.en -V/media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus/en.vcb.classes opt
(1.1) running mkcls  @ Fri Apr 24 22:10:39 CEST 2015
/home/gillin/moses/training-tools/mkcls -c50 -n2 -p/media/2tb/ccexp/corpus.exp/train-clean.ru -V/media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus/ru.vcb.classes opt
Executing: /home/gillin/moses/training-tools/mkcls -c50 -n2 -p/media/2tb/ccexp/corpus.exp/train-clean.ru -V/media/2tb/ccexp/phrase-clustercat-mgiza/work.en-ru/training/corpus/ru.vcb.classes opt

Is there a way such that i can grep all the lines that contain the output of $(date)?

Currently I'm using this regex:

[a-z].*[1-9] [0-2][1-9]:[0-6][0-9]:[0-6][0-9] CEST 2015

And it catches line like

preparing corpus @ Fri Apr 24 22:10:39 CEST 2015

But i need the full line:

(1) preparing corpus @ Fri Apr 24 22:10:39 CEST 2015

And also the year and time is sort of hard coded. Is there a better regex or unix tool that can extract lines with $(date) outputs?

Upvotes: 1

Views: 1465

Answers (1)

Cyrus
Cyrus

Reputation: 88583

Try this:

unalias grep
grep --color=never '.*[a-z].*[1-9] [0-2][1-9]:[0-6][0-9]:[0-6][0-9] CEST 2015' file

Upvotes: 1

Related Questions