If I understand the requirement, you might need to use two Pipes: one to 
analyze what the file looks like, the second to do the actual manipulation. I 
know you said the second filed isn't always there, but if the second field, if 
there, always starts in column 20 (or wherever), then I think the first Pipe 
does this:

- split the file into two streams, with and without quotes (throwing away those 
that start with blanks)
- each stream finds the longest field2
- streams rejoin and you take the longest

Now you have a spec you can use to parse. Repeat as needed for other fields. 
Fugly but what can ya do?

Hm, I'm wondering if you could use OVERLAY (once you've split the file into 
quoted/non-quoted for a given field) to find the longest record: if you OVERLAY 
all the records, the longest one winds up "winning". This would also avoid 
confusion from blank fields.

I'm really not sure I grok all the subtleties of what you need; maybe more 
sample data would help?

...phsiii
-----Original Message-----
Date:    Tue, 20 Oct 2009 14:33:32 -0400
From:    Glenn Knickerbocker <[email protected]>
Subject: parsing a word *or* a quote-delimited string

I have one of those annoying input files with fields that contain
*either* blank-delimited words *or* quote-delimited strings.  The
program that generates it politely looks for the longest value in the
first field and pads the field to that length to line them up in
columns:

  AMDSADVI  PLX       'PL/X-390 V02 R04 M00'  'HLASM R5.0'
  AMDSAEDR  PLX       PLX241                  ASMHL4.0    

but it doesn't *report* that length, and the second field isn't present
in every record (and of course the records are padded to a fixed length)=20
so I can't just peek the first record to find its column.  I need to do
a bunch of manipulations on each field, taking out unwanted characters,
using LOOKUP to replace some values, etc., and then put the whole record
back together.  Anybody have a handy way to split up a record with
fields like this?

I *think* I can trust that the quoted values never start or end with
blanks, if that helps any.  I suppose, given that, I could find the
records where the first field starts with a quote, CHOP those AFTER
STRING "' ", and just CHOP the others at a blank.

Reply via email to