Well, Sir Rob did suggest offline a problem with my "CHANGE" stage technique, 
citing a string consisting of a single comma within double quotes: 
“field1”,”field2”,”,”,”Field4”…

So as a response, I suggested (using ‘01’x to temporarily replace single commas 
in double quotes, and ‘00’x to replace the command field separator).  With a 
better example that shared with Sir Rob, the following seems to do it:
. . .
in.1='"F1a data","F2a data","F3a data",",","F4a data",",",","F7a data"'
in.2='"F1b data","F2b data","F3b data",",","F4b data",",",","F7b data"'
in.0=2

'PIPE (END ?)' ,
   '| STEM in.' ,
   '| PREFACE LITERAL Displaying input source:' ,
   '| APPEND LITERAL ---' ,
   '| CONSOLE' ,
   '| BUFFER' ,              /* Display all input in order */
   '| DROP FIRST 1' ,
   '| DROP LAST 1' ,
   , /* Now temp change single comma in double quotes ( "," )        */
   , /* to '01'x in quotes ( "1" ) in double quotes                  */
   '| CHANGE /",",","/       /","'||'01'x||'","/' ,
   , /* Now field separator commas in double quotes   ( "," )        */
   , /* to '00'x in quotes ( "0" ) in double quotes                  */
   '| CHANGE /","/           /"'||'00'x||'"/' ,
   , /* Now restore the single comma in double quotes ( "," )        */
   '| CHANGE /"'||'01'x||'"/ /","/' ,
   '| SPECS FS 00 F2 1 /~/ NW F1 NW F7 NW' , /* Show selected fields */
   '| PREFACE LITERAL Now display Fields 2 (TWO), 1 (ONE),' ,
                     'and 7 (SEVEN)' ,
   '| APPEND LITERAL ---' ,
   '| BUFFER' ,                        /* Display all input in order */
   '| CONSOLE'
. . .

Would that handle it?  Three CHANGE stages (the rest are just part of the 
“proof”) in place of the other complex code?

-----Original Message-----
From: CMSTSO Pipelines Discussion List [mailto:[email protected]] On 
Behalf Of Glenn Knickerbocker
Sent: Thursday, August 20, 2015 13:42
To: [email protected]
Subject: Re: CSV data specs

On 8/20/2015 11:18 AM, Mike Walter wrote:
> Thinking outside the box, the real comma of importance is always
> between two double-quotes, right?  Ala:  "Field1 data","Field 2 data,
> with a comma, and another comma","Field3 data","and so on"
> How about a simple stage: | CHANGE /","/"~"/

Not quite so simple, but:  The commas you want to preserve will always come 
after an *odd* number of double quotes.  If you knew the maximum number of 
fields, you could list all the even-numbered ones to change them in--except, 
unfortunately, CHANGE only takes a list of ranges, not inputRanges, so you 
can't do it quite this neatly:

  ... | change (fs " f2 f4 f6 f8 f10) /,/ x05
      | change /"//
      | xlate , 05 05 ,
      | ...

But you can do it one field at a time and ADDPIPE more CHANGEs until you've got 
'em all, something like:

  'addstream input q'

  'addpipe (end ?) *: | q: locate /"/ | *.in.q:'      ,
    '? q: | out: faninany | xlate , 05 05 , | *.out:' ,
    '? *.out: | out:'

  'select input q'
  'peekto'
  Do While rc = 0

    'addpipe (end ?) *: | change fs " f2 /,/ x05' ,
      '| change /"// 2 | q: locate /"/ | *.in:'   ,
      '? q: | out: faninany | *: ? *.out: | out:'

    If rc = 0 then 'peekto'
  End

¬R

Reply via email to