SORT stage v1.1

Pipelines v2.1

 

Purpose, Operands, Streams, Usage, Examples, Related

Home

 

Examples need sorting out!

 

Syntax

 

                      ┌─NOPAD────┐               ┌─Ascending──┐
>>──SORT────────────┼──────────┼─────────────┼────────────┼──────────────────────><
          COUNT──  └─PADchar─┘  └─ANYcase─┘  Descending
          └─UNIQue─┘                             └─┤ Group ├──┘
 
Group:
 
   ┌─<─────────────────────────────────────────┐
                 ┌─Ascending──┐               
──columnrange──┼────────────┼──────────────────────────────────────────────────
                  └─Descending─┘  NOPAD────
                                  └─PADchar─┘
 
Notes:
(1)  columnrange is unsigned.
 

Purpose

 

Use the SORT stage to arrange records in ascending or descending order. SORT reads records from its primary input stream and writes the records to its primary output stream. SORT reads all records from its primary input stream before it writes any records to its primary output stream.

By default, SORT compares the entire record to determine the order of records in its output stream. However, you can specify one or more key fields to determine the sequence of records in the output stream. A key field is a specific range of columns within each record.

 

Operands

 

COUNT

Specifies that each record in the output stream is prefaced with a 10-character field that represents the number of records with identical key fields. The number is right-justified with leading spaces. Records are considered to be identical if the specified key fields contain the same data. If a key field is not specified, records are considered to be identical if they contain exactly the same data.

When COUNT is specified, only the first record is retained; duplicate records are discarded.

 

UNIQue

writes all unique records and the first record of each set of duplicate records to the output stream. Records are considered to be identical if the specified key fields contain the same data. If a key field is not specified, records are considered to be identical if they contain the same data.

 

NOPAD

specifies that shorter key fields are not extended with a pad character before they are compared with longer key fields in other records. The NOPAD operand can be specified in two positions on the SORT stage:

 

 

If NOPAD is specified before the columnrange operands or if columnrange is not specified, NOPAD applies to the entire record. This is the default.

If you specify NOPAD after columnrange, NOPAD only applies to that particular key field.

 

PAD

specifies that shorter key fields are extended with a pad character before they are compared with longer key fields in other records. The PAD operand can be specified in two positions on the SORT stage:

 

 

If PAD is specified before the columnrange operands or if columnrange is not specified, PAD applies to the entire record.

 

If you specify PAD after columnrange, PAD only applies to that particular key field.

 

char

is the pad character.

 

ANYCase

specifies that key fields are compared in uppercase. In effect this means that a non-case-sensitive comparison is made when sorting the records.

 

Ascending

sorts records in ascending order. The ASCENDING operand can be specified in two positions on the SORT stage:

 

 

If ASCENDING is specified and columnrange is not specified, ASCENDING applies to the entire record. This is the default.

If you specify ASCENDING after columnrange, ASCENDING only applies to that particular key field.

 

Descending

sorts records in descending order. The DESCENDING operand can be specified in two positions on the SORT stage:

 

 

If DESCENDING is specified and columnrange is not specified, DESCENDING applies to the entire record.

If you specify DESCENDING after columnrange, DESCENDING only applies to that particular key field.

 

columnrange

is an unsigned integer column range which defines a key field to sort on. If you do not specify columnrange, the complete record is compared. If you specify more than one column range, you must place at least one space between each one that you specify.

 

Streams

 

The following streams are used by the SORT stage:

 

Stream

 

Action

 

 

Primary input stream

SORT reads all records from its primary input stream before writing any output records.

Primary output stream

After sorting the records read from the input stream, SORT writes the records to its primary output stream.

 

Usage

 

1.

SORT delays the records until end-of-file is reached on its primary input stream.

 

2.

If you do not specify COUNT or UNIQUE, records that are identical or have specified key fields that are identical remain in the same order as in the input stream.

 

3.

If the key fields in two records are of differing lengths when SORT is determining their order in the output stream, a position that is not present in one record is less than the contents of a record that has any character in that position. Use the PAD operand to extend a key field with a specific character.

 

4.

When you specify more than one column range, the records are sorted within each range. For example:

 
   **** Top of file ****
 1 Address Rxpipe
 2
 3 'pipe literal /a b c@b b a@b a a/',
 4    '| split at string /@/',
 5    '| sort 5 1 3',
 6    '| console'
 7
 8 Exit 0
   **** End of file ****
 
output:
b a a
b b a
a b c
 

5.

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

???

 

Examples

 

1)

A file list sorted by date and time

????

 

2)

Duplicate sort

????

 

3)

Recursive sort

????

 

4)

Sort

????

 

5)

Sorting a paragraph

????

 

6)

Sorting a range of records

????

 

Related

 

COLLATE, LOOKUP

 

History

 

Version

 

Date

Action

Description

Pipelines

1.1

27.12.2021

changed

Application-wide rewrite.

2.1

1.0

06.09.2007

created

First version.

1.0