STRIP stage v1.1

Pipelines v1.9

 

Purpose, Operands, Streams used, Usage notes, Examples, See also

Home

 

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 used

 

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 notes

 

     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

 

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:

 

pipe < myfile.txt 
     | locate                         .* Discard blank-lines.
     | xlate w-1;* x20 @ x09 @        .* Change spaces/tabs to at(@) chars.
     | split before str /@/           .* Split at each at(@), start new record.
     | strip trailing anyof /@/       .* Reduce records to length zero.
     | nlocate 1                      .* Select only null/empty records.
     | count                          .* Count the records.
     | specs /The number of bytes which could be saved is:/ 1 1-* nw
     | cons                           .* Display the result.
 

See also

 

Reference the following links for additional information:

 
CHOP, JOIN, PAD, SPECS, SPLIT