1

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?

alvas
  • 115,346
  • 109
  • 446
  • 738

1 Answers1

1

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
Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • this doesn't catch the `(1)` at the start of the sentence. – alvas Apr 25 '15 at 08:17
  • I've updated my answer. Which version of grep and which operating system do you use? – Cyrus Apr 25 '15 at 08:22
  • It removes an `alias` with additional options like `--color=auto`. – Cyrus Apr 25 '15 at 08:54
  • Note you don't need to `unalias grep`. To make `grep` behave circunventing the alias, just say `\grep`. See [Why start a shell command with a backslash?](http://stackoverflow.com/q/15691977/1983854) for example. – fedorqui Apr 28 '15 at 11:06