Match a pattern and print whole line containing matched pattern.

Well.. I was wondering to capture whole line, when I have already one field, and I did it with the help of my friend via awk.

A simple “awk” trick to match a pattern and print whole line containing matched pattern.

# cat <any_large_file/log>|awk ‘$3 ~ /<pattern to look for>/ {print $_}’

It will match a pattern in 3rd field of supplied file and if pattern found whole row/line will be printed on standard output.

Cheers!!

Advertisements

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 )

Google+ photo

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

Connecting to %s