bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: egrep: question


From: Bob Proulx
Subject: Re: egrep: question
Date: Wed, 10 Dec 2003 22:21:41 -0700
User-agent: Mutt/1.3.28i

Jeremy C. Reed wrote:
> roni wrote:
> > i'd like to search a file, and every time i bump into the word
> > "start", i'd like to print out all lines until i bump into the word "stop".
> > and then proceed.. - to print out all the paragraphs in that file that
> > start with "start" and end with "stop".
> 
> Try sed.
> Have  a look in the "sedfaq". It has examples.

Of course I am sure you can do it in sed.  But the way to have the
process repeat for multiple sets of start and stop blocks escapes me
at this moment.

I think in this case I would use Awk, Perl, or my personal preference
of Ruby.  In this case the Ruby and Perl programs can be identical.
If it was really this simple I would use Awk since it so prevalent.

  awk '/start/,/stop/{print}'

  ruby -lne 'print if /start/ .. /stop/'

  perl -lne 'print if /start/ .. /stop/'

As to your original question about grep/egrep, it does not have
decision making capabilities and switching on and off such as this is
out of scope for it.  You need to use one of the other programs.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]