On Wed, 9 Feb 2000, Matt Tilley wrote:

> OK, here goes.  My problem stems from dealing with a file that contains
> lines.  Some of the lines I want to keep, while I want to discard others
> (based on the value of the field of the first column).  It seems that the
> nutshell book deals more with files than with variables (this could just be a
> stumbling block of mine)
> 
> I am looking for groups of lines that belong together - for instance, whenever
> a line starts with "HCA" I want to save that line to a file and append the
> following lines as long as they begin with IX????? or IY????? (the "?" are
> place markers - I know that I will have a five digit number there).  As soon
> as the next HCA comes along, I want to do the same thing again.

So long as no other lines begin with IX or IY followed by a digit, this is
simple (once you know how, of course!)

egrep "^HCA|^I[XY][0-9]" filename

Note that those are not ctrl-H or ctrl-I, but a carrat followed by the H
or I respectively, which indicates that what follows the carret is at the
beginning of the line.

Perl be damned!  I know you'll probably get tons of messages about perl
ways to do this, but this is shorter and faster than most, if not all of
them... :)  Assuming that you're using GNU egrep, which is extremely
likely (almost a certainty) if you're on a linux system (Ron Schwartz,
Learning Perl, ch 1, p12).

Derek Martin
President, He-Man Perl Haters Club
(o.k., not really)

-- 
"Quis custodiet ipsos custodes?"    "Who watches the watchmen?" 
-Juvenal, Satires, VI, 347 

Derek D. Martin      |  Senior UNIX Systems/Network Administrator
Arris Interactive    |  A Nortel Company
[EMAIL PROTECTED]  |  [EMAIL PROTECTED]
-------------------------------------------------


**********************************************************
To unsubscribe from this list, send mail to
[EMAIL PROTECTED] with the following text in the
*body* (*not* the subject line) of the letter:
unsubscribe gnhlug
**********************************************************

Reply via email to