[CentOS] grep

Tue Aug 28 14:27:31 UTC 2007
Stephen Harris <lists at spuddy.org>

On Tue, Aug 28, 2007 at 10:13:00AM -0400, Scott McClanahan wrote:
> On Tue, 2007-08-28 at 10:08 -0400, Stephen Harris wrote:
> > > Not a CentOS specific question, although I am running grep on CentOS 4.3
> > > but how would you grep out a series of lines in a file starting at a
> > > specific point.  For instance, if I have a file named foo and I want to
> > > grep out the next 5 lines after the first and only instance of the
> > > string "bar" how could I pull that off?  Thanks so much.
> > 
> > What do you mean by "grep out" ?  Do you want to display those lines,
> > or skip those lines?  Do you want to see the "bar" line?  Is that included
> > in the 5 lines?
> > 
> > Anyway, you probably want to use "sed" here, rather than "grep".
> > 
> I'd like to skip those lines.  I'd like to skip the line with "bar" and
> the following five lines.

Like this?

  $ cat xx            
  line 1
  line 2
  line bar
  line after 1
  line after 2
  line after 3
  line after 4
  line after 5
  line after 6
  line after 7
  $ sed '/bar/,+5d' xx
  line 1
  line 2
  line after 6
  line after 7

-- 

rgds
Stephen