Grep for Two or More Expressions
November 9, 2010 1 Comment
Unfortunately a database of mine crashed. Fortunately, I have log files with the data. I need the timestamp and the data.
The lines in the log files look something like this:
####### collect $TIMESTAMP #########
*GARBAGE
*GARBAGE
*GARBAGE
$ID:=$DATASET
*GARBAGE
It’s been years since I’ve done anything more than a simple grep. I wasn’t even sure which grep I needed… egrep? fgrep? grep?
I can use this regex for the timestamp line:
\#\ collect
I can use this regex for the dataset line:
\:\=
But how can I put them together? It’s probably of no surpise that I can use the ‘|’ operator like so:
egrep '\#\ collect|\:\=' 2010-09-25.log
Are you a Git user? Let me help you make project management with Git simple. Checkout Gitpilot.
That’s it! Follow me on Twitter @jprichardson and read my blog on entrepreneurship.
-JP
Pingback: Iterate Over Files in Bash « Procbits