Here is a quick, non optomized perl script:

while (<>) {
  next unless (/^HCA/);
  print $_;
  while (<>) {
    last unless (/^I[XY]\d\d\d\d\d/);
    print $_;
  }
}

There are more efficient ways to do this then the above perl, but that is
sufficient...

- Marc

On Wed, 9 Feb 2000, Matt Tilley wrote:

> Sorry for the long post, but tried to include enough info so that people can
> help.
> 
> Also, there is probably a better group to post to, but a quick search for
> "script" in newsgroups didn't turn up anything that led me to believe that the
> question would be better directed to another group (if I'm wrong - please just
> point me in the right direction, I'll post there and sorry for the bother).
> 
> 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.
> 
> Again, there are some lines that contain starting characters different than
> those above (or just blank lines) that I just want to discard.
> 
> Here is a quick example of the file that I want to work with:
> 
> START:
> 
> Garbage line that I want to discard
> 
> More garbage
> 
> HCA would like to keep this line
> IY45678 - and keep this line under the one above it (once I get the structure
> I can do more)
> IX89374 - with the rest.
> 
> More garbage that isn't wanted
> HCA would like to also keep this line, appending it to those above
> IX84956 - but preferably separated by a line
> IY74658 - this should be simple but I'm having a mental block. Once over the
> block
> IY34567 - I feel like a mental switch will close and I will begin to be more
> productive
> IX84755 - with my scripts (otherwise they seem way to simple (almost like a
> batch file)
> 
> END!
> 
> 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):
> 
> cat myfile | while read line
>  do
>     for i in $line
>       do
>         if [ [ $i = IX????? || IY????? || HCA ] ]
>             # would like to exit if true to the while loop and dump the line
>             # to a file - possibly setting a flag to indicate that HCA is true
> (i.e., hcaflag)
>             # as soon as another HCA or an unwanted word is encountered
>             # print a blank line, discard unwanted line or start process over
>             # again
>             then  exit to while loop if true
> 
>             else  discard line and get next line from myfile
>         fi
> 
>         if [ hcaflag ]
>             then if [ [ $i = IX????? || IY????? ] ]
>                         then  echo line to file, etc.
> 
> Is this the right way to go about this (or haven't I explained it in enough
> detail to understand my problem?).
> 
> I'm not in scripting school (although I've been through one a while back), and
> I'm not doing this for anyone else but me (just to help me with my scripting
> skills).  I'm willing to put some time into this, but feel as if there maybe
> an easier way that I'm overlooking (am I making this way too difficult?).  The
> purpose behind this is to expedite the handling of large files indicating the
> fileset status on my AIX boxes (yes, I know that this isn't an AIX list, but
> I'm always monitoring this list because of my interest in Linux (have one
> P-166 running RH6.0 and on/off luck with running RH on my Dec Alpha (both at
> home)).
> 
> Sorry for the long message, but wanted to be sure that I gave enough
> information (hoping that I achieved this).
> 
> TIA
> 
> - Matt
> 
> 
> 
> 
> **********************************************************
> 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
> **********************************************************
> 


**********************************************************
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