Computing.Net > Forums > Unix > grep shell script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

grep shell script

Reply to Message Icon

Name: mehul
Date: August 28, 2003 at 14:38:19 Pacific
OS: sun
CPU/Ram: sun
Comment:

Hello,
I have a little trouble with grep...what i have is a file with many lines and any of the line may contain a word "error" , i want to grep this word "error" and print 5 lines above and 5 line below including the line in which "error" is present....

i can grep for the word error and print line which contains only error but how do i print 5 lines above and 5 line below of the line were "error" is found

Appreciate your help

Thx in advance

Mehul



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: August 28, 2003 at 17:51:26 Pacific
Reply:

If it works for your version of grep the -A and -B flags specify lines before and after a pattern match.

You can also do it with sed

sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h

For other tricks with sed look here:

http://www.student.northpark.edu/pemente/sed/sed1line.txt


0

Response Number 2
Name: mehul
Date: August 29, 2003 at 14:22:29 Pacific
Reply:

Thx david it worked


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: grep shell script

Shell Script www.computing.net/answers/unix/shell-script/1507.html

more on simple shell scripts www.computing.net/answers/unix/more-on-simple-shell-scripts/4827.html

Shell script with regular expressio www.computing.net/answers/unix/shell-script-with-regular-expressio/4397.html