locate.rex

Pipelines v2.1

 

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

Home

     **** Top of file ****
   1
   2 /* The following pipeline handles four input arguments:
   3
   4    arg 1. The name of a file to read.
   5    arg 2. The type of locate: 'string', 'anyof' or 'pattern'.
   6    arg 3. The number of records to search.
   7    arg 4. The text string or pattern to locate.
   8
   9    The pipeline opens the input file and searches each record for the specified text.
  10    For each record that contains the text, up to and including the count specified in (arg 3), 
  11    the pipeline constructs an output record comprising; the number of the record containing the
  12    phrase or pattern, followed by the record content.
  13
  14    Note. that if a record that matches the search contains the hexadecimal characters x'fe' or
  15    x'ff', then the x'fe' and x'ff' literals in the pipeline must be substituted for other
  16    characters that are not present in the record. */
  17
  18 Address Rxpipe
  19
  20 Parse Arg file ',' type ',' number ',' str
  21
  22 'pipe (endchar ?)',
  23      '<' file ,                                     /* Read input file. */
  24      '| specs /Line:/ 1 recno strip nw 1-* nw',     /* Record number and append the record. */
  25      '| locate w3-*' type '/'str'/',                /* Locate the argument in the record section. */
  26      '| take' number ,                              /* Take the records.*/
  27      '| specs /'file'/ 1.110 xff n 1-* n',          /* Put the file path in column 1, then x'ff', */
  28         ,                                           /* ..and append the record. */
  29      '| xlate ws xff w1 \ xfe',                     /* Change backslashes in the path to x'fe'. */
  30      '| specs ws xfeff w-1;* 1',                    /* Discard path and filename, keep the record. */
  31      '| c: count',                                  /* Count the occurrences. */
  32      '| b: fanin 1 *',                              /* Read stream 1 then 0. */
  33      '| console',                                   /* Display the record on the console. */
  34      '?',
  35      'literal /Searching file: 'file'/',            /* Tell the user what is executing. */
  36      '| specs w1-2 1 ws ''\'' w-1 nw',
  37      '| b:',                                        /* Back to pipeline 0. */
  38      '?',
  39      'c:',
  40      '| specs 1-* 1 /occurrences found/ nw x0a n',  /* Tell the user the # of occurrences found */
  41      '| console'
  42
  43 Exit 0
     **** End of file ****
 

 

 
Validate the arguments!