The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 01-21-2008
airman_ole airman_ole is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 2
grep -n lines before and after

Hi,

is it possible to grep a pattern that will include the "n" lines before and after the line where the pattern have been found?

e.g.

#this contains the test.file
line1
line2
line3
line4
line5

then a grep command to search the word "line3"
and the output should be 1 (or n) line before that line and 1 (or n) line "after" that line.

dessired output of the grep command

line2
line3
line4


Thanks in advance.