|
Locate |
Pipelines v1.9 |
.* Example by TenFiftyTwo(c). |
.* The following pipeline handles four input arguments:.*.* &arg1. The name of a file to read..* &arg2. The type of locate: 'string', 'anyof' or 'pattern'..* &arg3. The number of records to search..* &arg4. The text string or pattern to locate..*.* The pipeline opens the input file and searches each record that it reads for the specified text..* For each record that contains the text, up to and including the count specified in &arg3, .* the pipeline constructs an output record comprising; the number of the record containing the.* phrase or pattern, followed by the record content. .* Note. that if a record that matches the search contains the hexadecimal characters x’fe’ or x’ff’,.* then the x’fe’ and x’ff’ literals in the pipeline must be substituted for other characters that are.* not present in the record. pipe (endchar ?)
< &arg1 .* Read input file. | specs /Line:/ 1 recno strip nw 1-* nw .* Record number and append the record. | locate w3-* &arg2 /&arg4/ .* Locate the argument in the record section. | take &arg3 .* Take as many records as the argument specifies. | specs /&arg1/ 1.110 xff n 1-* n .* Put the filepath in column 1, then x’ff’, and append.. .* ..the record. | xlate ws xff w1 \ xfe .* Change backslashes in the path to x’fe’. | specs ws xfeff w-1;* 1 .* Discard the filepath and filename, keep the record. | c: count .* Count the occurrences. | b: fanin 1 * .* Read stream 1 then 0. | console .* Display the record on the console. ? literal /Searching file: &arg1/ .* Tell the user what is executing. | specs w1-2 1 ws ‘\’ w-1 nw | b: .* Back to pipeline 0. ? c: | specs 1-* 1 /occurrences found/ nw .* Tell the user the number of occurrences found. X0a n | console