changing-a-csv-field.rex

Pipelines v2.1

 

.....|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+....10...

Home

     **** Top of file ****
   1
   2 /* The following pipeline reads the input file: isbn.csv and feeds the records to the
   3    called pipeline: parse-csv.rex, which replaces the CSV field delimiter: ',' (comma) with a
   4    new delimiting character: x'ff'.
   5
   6    The pipeline is then able to use this new field delimiter in the XLATE stage to isolate field
   7    number two in order to convert the contents to uppercase. After the translation, the original
   8    delimiter is restored and the records are displayed on the console.*/
   9
  10 Address Rxpipe
  11
  12 'pipe < &installdrive:\&installpath\examples\input\isbn.csv',
  13      '| call "&installdrive:\&installpath\examples\subroutine\parse-csv.rex"',
  14              ',',                                  /* Current CSV delimiter. */
  15              "ff"x,                                /* New CSV delimiter. */
  16      '| xlate fs xff f2',                          /* Translate field #2 to uppercase. */
  17      '| change xff /,/',                           /* Restore the original field delimiter. */
  18      '| cons'                                      /* Display on the console. */
  19
  20 Say 'Hit Enter to close..'
  21 Parse Pull
  22
  23 Exit 0
     **** End of file ****
 

Console output

 
.....|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+....10...
   1 1984,GEORGE ORWELL,paperback,978-0451524935,268
   2 Animal Farm,GEORGE ORWELL,paperback,978-0451526342,144
   3 Brave New World,ALDOUS HUXLEY,hardback,978-0060929879,288
   4 "Eats, Shoots & Leaves",LYNNE TRUSS,paperback,978-1592400874,209
   5 Fahrenheit 451,RAY BRADBURY,hardback,978-0345342966,208
   6 Jane Eyre,CHARLOTTE BRONTE,hardback,978-0142437209,532
   7 Wuthering Heights,"EMILY BRONTE",paperback,978-0141439556,416
   8 Agnes Grey,ANNE BRONTE,hardback,978-1593083236,256
   9 Walden,HENRY DAVID THOREAU,paperback,978-1420922615,156
  10 Walden Two,B. F. SKINNER,paperback,978-0872207783,301
  11 Hit Enter to close..