max-length.rex

Pipelines v2.1

 

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

Home

     **** Top of file ****
   1
   2 /* The following pipeline handles one input argument:
   3
   4    arg 1. The maximum output record length.
   5
   6    The pipeline reads its input and formats each paragraph so that, where possible, each
   7    record is no longer than 'length' characters in length. If an input record comprises a single
   8    word which is longer than 'length' characters in length, the record remains unchanged.
   9
  10    Note. leading, embedded and trailing whitespace is discarded during the process. */
  11
  12 Address Rxpipe
  13
  14 Parse Arg length
  15
  16 'pipe (stagesep ~)',
  17      'in',                    /* Read from input. */
  18      '~ strip trailing',      /* Trim off trailing whitespace, so we can find blank records. */
  19      '~ split',               /* Split into individual words. */
  20      '~ join * x20' length ,  /* Join records up to a maximum length of 'length'. */
  21      '~ out'                  /* Write to output. */
  22
  23 Exit 0
     **** End of file ****
 

 

 
Validate the arguments!