Matt Tilley wrote:
>
> Sorry for the long post, but tried to include enough info so that people can
> help.
The more info the better.
> 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).
>
> 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.
Ok, awk or perl would be your best bet.
> Again, there are some lines that contain starting characters different than
> those above (or just blank lines) that I just want to discard.
This may be a dangerous assumption...
Here's a simple enough way to do it with awk:
cat infile | awk '$1 == "HCA" || $1 ~ /^I[XY][0-9]+/ {print}' > outfile
or if you want each HCA record preceded by a blank line:
cat infile | awk '$1 == "HCA" { print "\n" $0 }; $1~/^I[XY][0-9]+/ {print}' > outfile
> BTW, I would like to use ksh for this (will look into other ways (such as
> perl) after I close my knowledge gap in places like this). My thoughts on
> this were this (just to at least show that I've been thinking about it):
>
[code deleted]
While you could probably get it working with some sort of ksh hack, it's
always better IMO, to use the toolbox you have available to you. awk is
perfectly suited to do this type of thing. (perl would be more fun though :)
-Matt
--
Matthew W. Herbert x75764
Spectrum Advanced Applications
http://www.aprisma.com/
mailto:[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
**********************************************************