locate-and-file.rex |
Pipelines v2.1 |
.....|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8....+....9....+....10... |
**** Top of file ****
1
2 /* The following pipeline handles five input arguments:
3
4 arg 1. The name of a file to read.
5 arg 2. The type of locate: 'string', 'regex', 'anyof' or 'pattern'.
6 arg 3. The number of records to search.
7 arg 4. The text string or pattern to locate.
8 arg 5. The name of the file to which matches are written.
9
10 The pipeline opens the input file and searches each record that it reads for the specified text.
11 For each record that contains the text, up to and including the count specified in (arg 3),
12 the pipeline constructs an output record comprising; the name of the file, the number of the record
13 containing the phrase or pattern, followed by the record content.
14 The results are written to the console and to an output file specified in the &arg5 argument.
15
16 Note. that if a record that matches the search, contains the hexadecimal characters x'fe' or x'ff',
17 then the x'fe' and x'ff' literals in the pipeline must be substituted for other characters that are
18 not present in the record. */
19
20 Address Rxpipe
21
22 Parse Arg infile ',' type ',' number ',' str ',' outfile
23
24 'pipe (endchar ?)',
25 '<' infile , /* Read input file. */
26 '| a: fanout', /* Send a copy to both streams. */
27 '| literal /'infile'/', /* The name of the file we are processing. */
28 '| take 1', /* Take only the first record. */
29 '| specs /Searching:/ 1 1-* nw x0a n', /* Construct the output message. */
30 '| console', /* Display it. */
31 '?',
32 'a:',
33 '| specs /Line:/ 1 recno strip nw 1-* nw', /* Record number and append the record. */
34 '| locate w3-* 'type' /'str'/', /* Locate the argument, in the record section. */
35 '| take' number , /* Take as many records as the argument specifies. */
36 '| specs /&arg1/ 1.110 xff n 1-* n', /* Put the file path in column 1, then x'ff' and.. */
37 , /* ..append the record. */
38 '| xlate ws xff w1 \ xfe', /* Change backslashes in the path to x'fe'. */
39 '| specs ws xff w-1;* 1', /* Isolate the record data. */
40 '| console', /* Display the record on the console. */
41 '| >' outfile /* Write to output file. */
42
43 Say 'Hit Enter to close..'
44 Parse Pull
45
46 Exit 0
**** End of file ****
|
Validate the arguments!