How To grep n Lines Before In Solaris

Hi,

I like to show how to get the n lines before a pattern search using grep in Solaris. First of all, Solaris grep command not have a option to get the lines before or after from a match. You must use ggrep compliance to unix standard. Let me see show a pair of examples;

Test 1, this comamnd show the four previous lines from match ‘ORA-00313’;

cat alert_db.log | /usr/sfw/bin/ggrep -B 4 ORA-00313

Test 2, this command show the previous line from match ‘ORA-00313’;

cat alert_db.log | /usr/sfw/bin/ggrep -B 1 ORA-00313

HTH – Antonio NAVARRO

 

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 )

Google+ photo

You are commenting using your Google+ 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