STRIP stage v1.2

Pipelines v2.1

 

Purpose, Operands, Streams, Usage, Examples, Related

Home

 

Need line numbers for example 3

 

Syntax

 
           ┌─BOTH───────────────────────────────────────────────────────────┐
>>──STRIP──┼────────────────────────────────────────────────────────────────┼────────><
           │ ┌─BOTH─────┐                                                   
           └─┼──────────┼──┬─────────┬──┬─────────────────────────────────┬─┘
             LEADING──┤  └─ANYCase─┘  charrange───────┬──┬──────────┬─┘
             └─TRAILING─┘               STRing─┬─string─┘  └─maxstrip─┘
                                        └─ANYof──┘
 
Notes:
(1) The maxstrip operand cannot be specified without specifying other operands.
 

Purpose

 

Use the STRIP stage to remove leading and/or trailing characters from input records. STRIP reads records from its primary input stream; removes the specified characters and writes the resulting records to its primary output stream. If no operands are specified; STRIP removes leading and trailing whitespace from the records (both space (X'20) and tab (X'09) characters are considered to be whitespace). If you only specify the BOTH, LEADING or TRAILING operands; whitespace is removed from both ends of the records, the beginning of the records or the end of the records, respectively. With additional operands; the specified target characters are removed.

 

Operands

 

BOTH

removes consecutive occurrences of the specified characters from the beginning and the end of input records. This is the default.

 

LEADING

removes consecutive occurrences of the specified characters from the beginning of input records.

 

TRAILING

removes consecutive occurrences of the specified characters from the end of input records.

 

ANYCase

specifies that charrange or string is compared with the input record in uppercase. In effect this means that a non-case-sensitive comparison is made when selecting characters that are to be removed.

 

charrange

is a character range. STRIP removes leading or trailing occurrences of any of the characters in the range.

 

STRing

specifies that the string operand is a literal string of characters to remove.

 

ANYof

specifies that the string operand is a list of characters to remove. STRIP removes leading or trailing occurrences of any of the characters in the list.

 

 

string

is a string to locate.

 

maxstrip

specifies the maximum number of occurrences of the target character(s) or string to remove.

 

Streams

 

The following streams are used by the STRIP stage:

 

Stream

 

Action

 

 

Primary input stream

STRIP reads records from its primary input stream.

Primary output stream

After removing the specified characters from the records read from its primary input stream; STRIP writes the resulting records to its primary output stream.

 

Usage

 

1.

STRIP does not delay the records.

 

2.

If the STRIP stage discovers that its primary input or output streams are not connected, the STRIP stage ends.

 

3.

STRIP copies any null input records to its primary output stream.

 

4.

If all the characters in a record are removed, STRIP writes a null record to its primary output stream.

 

5.

STRIP verifies that its secondary input and output streams are not connected and then begins execution.

 

Examples

 

1.

The following example utilises the STRIP stage command in a pipeline which determines the number of bytes that could be saved by removing trailing whitespace:

 

   **** Top of file ****
 1 Address Rxpipe
 2
 3 'pipe < myfile.txt ',
 4    '| locate',                         /* Discard blank-lines. */
 5    '| xlate w-1;* x20 @ x09 @',        /* Change spaces/tabs to at(@) chars. */
 6    '| split before str /@/',           /* Split at each at(@), start new record. */
 7    '| strip trailing anyof /@/',       /* Reduce records to length zero. */
 8    '| nlocate 1',                      /* Select only null/empty records. */
 9    '| count',                          /* Count the records. */
10    '| specs /The number of bytes which could be saved is:/ 1 1-* nw',
11    '| cons'                            /* Display the result. */
12
13 Exit 0
   **** End of file ****

 

2.

In this example, the STRIP stage removes leading and trailing asterisks (*) and blanks from the input records.

 

prologue.txt (input)

 

   **** Top of file ****

 1 ***********************************************************************

 2 *                                                                     *

 3 *  THIS ROUTINE REMOVES LEADING OR TRAILING CHARACTERS FROM RECORDS   *

 4 *  READ FROM THE PRIMARY INPUT STREAM. THE ROUTINE WRITES OUTPUT      *

 5 *  RECORDS TO THE PRIMARY OUTPUT STREAM.                              *

 6 *                                                                     *

 7 ***********************************************************************

   **** End of file ****

 

'pipe < prologue.txt | strip anyof /* / | console'

 

output:

THIS ROUTINE REMOVES LEADING OR TRAILING CHARACTERS FROM RECORDS

READ FROM THE PRIMARY INPUT STREAM. THE ROUTINE WRITES OUTPUT

RECORDS TO THE PRIMARY OUTPUT STREAM.

 

3.

Removing blank records

 

This example shows you how to remove blank records from an input stream. The STRIP stage (line: ???) trims any whitespace (spaces and tabs) from the beginning and end of each input record and the LOCATE stage which follows (line: ???), discards any record of zero length.

 

Related

 
CHOP, JOIN, PAD, SPECS, SPLIT
 

History

 

Version

 

Date

Action

Description

Pipelines

1.2

27.12.2021

changed

Application-wide rewrite.

2.1

1.1

23.05.2011

added

The maxstrip operand; which specifies the maximum number of occurrences of the target character(s) or string to remove.

1.9

1.0

06.09.2007

created

First version.

1.0