Grep for Two or More Expressions

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

One Response to Grep for Two or More Expressions

  1. Pingback: Iterate Over Files in Bash « Procbits

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.