Converting a Comma-delimited File to Fixed-column Format

Qedit's "Divide" command can split a line at a fixed column position, or at the start of a specified string. The "Glue" command connects two lines together, by default at the end of the first line, or alternatively at a specified column.

These features are used in the following command file, which uses the "Divide" and "Glue" commands to convert a 4-field comma-delimited file to a fixed-length file with fields at columns 1,20,40 and 60. If the line contains an extra comma, it's marked for manual (personal) editing:

option nowarn
setjcw cierror,0
/set language text
/set length 256
/lq first > $null        { Go to top of file}
while cierror = 0 do     { until EOF do     }
 /divideq "," *          { split line at comma }
 /lq *+1 > $null         { move to second portion of line }
 /cq 1/1 "" ","(1/1)     { remove comma in column 1 }
 /divideq "," *          {   ....etc ...    }
 /lq *+1 > $null
 /cq 1/1 "" ","(1/1)
 /divideq "," *
 /lq *+1 > $null
 /cq 1/1 "" ","(1/1)
 setjcw qeditcount,0
 /cq ","," *             { <-----check for extra commas!}
 if qeditcount > 0
   /appq "<<sick puppy!" * { mark for later manual editing }
 endif
 /glueq (21,41,61) *-3   { Glue record back together, at specified columns}
 continue
 /lq *+1 > $null
endwhile
echo ALL DONE! Records requiring manual fixing marked "Sick Puppy"

....Back to the Qedit Q&A Page
....Back to the Suprtool Q&A Page