ZFILE sort: Sort an input file

Use this command to sort data from one or more input files.

Last updated

Added in 2024.

Requirements and restrictions

  • The parameters for this command are case-sensitive. You must enter the parameters exactly as shown in the syntax diagram.
  • You can enter this command only when get file storage (GFS) is available or when a memory file system (MFS) or fixed file system (FFS) is mounted on the /.tpfZfileTmpfile directory.

Format

Read syntax diagramSkip visual syntax diagram ZFILE sort  -b -d -f -i -k kstart,kend -m -n -o outfile -R recordseparator -r -T /.tpfZfileTmpfile-T tempdir -t fieldseparator -u path
-b
Specifies that leading blanks are to be ignored when sorting the input file. The -b parameter takes effect only when the -k parameter is specified.
-d
Specifies that only blank space and alphanumeric characters are used when sorting the input file.
-f
Specifies that the sorting comparison for the input file is not case-sensitive.
-i
Specifies that nonprintable Extended Binary Coded Decimal Interchange Code (EBCDIC) characters are to be ignored when sorting the input file.
-k
Specifies the start and end field number of a key within each record. The ZFILE sort command sorts the input based on the value of the key. If you do not specify the -k parameter, the whole record is treated as a single key starting with the first field. You can specify this parameter multiple times to declare multiple key fields.
kstart
The starting field number of a key within each record. Specify the starting field number in the format x.y, where x is a positive integer that represents the field and y is a positive integer that represents a character in that field. If you do not specify .y, the value defaults to .1, which indicates the first character of the specified field.

If the -b parameter is in effect, the character (y) is counted from the first nonblank character in the specified field. For example, x.1b refers to the first nonblank character in the field specified by x.

Similarly, if the -d parameter is in effect, the character (y) is counted from the first blank or alphanumeric character in the specified field. For example, x.1d refers to the first blank or alphanumeric character in the field specified by x.

kend
The ending field number of a key within each record. Specify the ending field number in the format x.y, where x is a positive integer that represents the field and y is a positive integer that represents a character in that field. If you do not specify .y, the value defaults to .1, which indicates the last character of the specified field.

If the -b parameter is in effect, the character (y) is counted from the first nonblank character in the specified field. For example, x.1b refers to the first nonblank character in the field specified by x.

Similarly, if the -d parameter is in effect, the character (y) is counted from the first blank or alphanumeric character in the specified field. For example, x.1d refers to the first blank or alphanumeric character in the field specified by x.

-m
Specifies that multiple input files are to be merged. The input files must already be sorted in the same order.
-n
Specifies that the input is sorted by treating the key field as a numeric value. If the input key begins with a minus sign, the value is treated as a negative number.
-o outfile
Specifies an output file for the sorted data. If data exists in the specified output file, it will be overwritten with the sorted data. The output file can be one of the input files. If the output file does not already exist, it will be created. If no output file is specified, the standard output stream is used.
-R recordseparator
Specifies a character as the record separator, which can be any character except A–Z.
-r
Specifies that the input file will be sorted in descending order.
-t fieldseparator
Specifies a printable character within each record to be used as the field separator. By default, the first blank space of a sequence of blank spaces acts as the field separator. All remaining blank spaces in the sequence of blank spaces are considered as part of the next field.
-T tempdir
Specifies a directory to be used for temporary files. This directory must already exist and is used internally by the ZFILE sort command during processing. For better performance, consider using a directory with an MFS mounted on it. If you do not specify this parameter, the /.tpfZfileTmpfile directory is used. This directory is also used to stage output for all ZFILE commands.
-u
Specifies that records with duplicate keys are included in the output only once.
path
The path name of one or more input files. If multiple input files are specified, the ZFILE sort command displays the sorted contents of each file in the order that you specified the file names. Specify a hyphen (-) to include the standard input (stdin) stream as input.

Additional information

  • Online help information is available for this command. To display the help information, enter one of the following commands:
    • ZFILE HELP sort
    • ZFILE HELP
    • ZFILE ?
    The correct command syntax is also displayed if you enter the syntax incorrectly.
  • If you specify the -b, -d, -f, -i, -n, or -r parameter before specifying the -k parameter, the ZFILE sort command applies that parameter to each -k parameter. Otherwise, you can specify each of these parameters independently on each field argument of the -k parameter. For each field argument of the -k parameter that you independently specify one of these parameters on, any globally specified parameters will not apply to the affected key field.
  • To consider only alphanumeric characters for comparison by using the -k parameter, specify both the -b and -d parameters.
  • You can sort data from multiple sources such as the standard input stream and files. To sort the output from another ZFILE command, you must pipe the output of the first command into the ZFILE sort command without specifying a path. If you specify a path name, the standard input stream is ignored.
  • You can redirect the standard input (stdin) stream from the keyboard to a file by specifying the redirection character (<) followed by the file name that you want the input read from.

    You can redirect the standard output (stdout) stream from the display terminal to a file by specifying one of the redirection characters (> or >>) followed by the file name that you want the output written to. The > character writes the output to a file. The >> character appends the output to an existing file.

    You can redirect the standard error (stderr) stream from the display terminal to a file by specifying one of the redirection characters (2> or 2>>) followed by the file name that you want the error output written to. The 2> character writes the error output to a file. The 2>> character appends the error output to an existing file.

    For example, the ZFILE dd command displays information from both stdin and stdout. You can use redirection to send the information from stderr to stdin, as well as redirect all of the contents of stdout to a file for storage. The following example converts the contents of a file to uppercase, redirects the number of bytes converted from stderr to stdin, and redirects all of the output from stdin to a file named test3.
    User:   zfile cat test1
    
    System: FILE0001I 14.26.32 START OF DISPLAY FROM cat test1
            this is a test
            END OF DISPLAY
    
    User:   zfile dd if=test1 conv=ucase >test3 2>&1
    
    System: FILE0003I 14.26.32 dd if=test1... COMPLETED SUCCESSFULLY. NO OUTPUT TO DISPLAY
    
    User:   zfile cat test3
    
    System: FILE0001I 14.26.32 START OF DISPLAY FROM cat test3
            THIS IS A TEST
            0.1 records in
            0.1 records out
            15 bytes transferred in 1 secs (15 bytes/sec)
            END OF DISPLAY
    Note: When you use the > or 2> character and the file that you are redirecting data to already exists, the file is overwritten and any data in that file is lost. If you do not want to overwrite the file, ensure that you use the >> or 2>> character.
  • You can use a vertical bar, or pipe (|), to direct data so that the output from one process becomes the input to another process. This type of one-way communication allows you to combine ZFILE commands on one line to create a pipeline. For example, the following pipeline uses the standard output (stdout) stream from the ZFILE ls command and redirects it to the standard input (stdin) stream of the ZFILE grep command to search for those lines containing the word Jan.
    ZFILE ls -l | grep Jan
    The result is filtered output from the ZFILE ls command displaying only the lines containing the word Jan in any position.

    You can use pipes only with a combination of ZFILE commands where the command on the left side of the pipe provides data through stdout and the right side accepts data through stdin.

  • You can use the following wildcard characters in the path name to select files that satisfy a particular name pattern:
    *
    Matches any string, including the empty string.
    ?
    Matches any single character.
    [..]
    Matches any one of the characters between the brackets. You can specify a range of characters by separating a pair of characters with a dash (-).
  • This command supports the following three quoting mechanisms, which allow you to override the special meaning of some characters:
    escape character (\)
    Preserves the literal value of the character that follows. To ignore the special meaning of a character, escape it by placing a backslash (\) in front of it. In the example that follows, environment variable PATH is /bin:/usr/bin:., the first dollar sign ($) is escaped because of the preceding backslash, and the second dollar sign takes on a special meaning.
    User:   ZFILE echo \$PATH is $PATH
    
    System: $PATH is /bin:/usr/bin:.
    single quotation marks (' ')
    Preserves the literal value of all characters between the opening single quotation mark and the closing single quotation mark. For example, entering ZFILE echo '*' displays an asterisk character (*). Without the single quotation marks, the files in the current working directory are displayed.
    quotation marks (" ")
    Preserves the literal value of all characters between the opening quotation mark and the closing quotation mark except the dollar sign ($), the backquote (`), and the backslash (\). This allows you to use the escape character inside quotation marks, which you cannot do inside single quotation marks.
    For example, entering ZFILE echo "\$PATH is \"$PATH\""
    displays $PATH is "/bin:/usr/bin:."
    If you want to use the literal meaning of any of the following characters, you always must use a quoting mechanism:
    In addition, use a quoting mechanism when any of the following characters are used in a way that takes on a special meaning, but you want to use the literal meaning:
  • The ZFILE sort command is based on a subset of the sort utility of the Portable Operating System Interface for Computer Environments (POSIX) standards.

Examples

The following example sorts the contents of the Example1.txt file. In this example, a colon (:) is used to separate the records and a comma (,) is used to separate the fields.
User:   ZFILE cat Example1.txt

System: CSMP0097I 14.06.40 CPU-B SS-BSS SSU-HPN IS-01
        FILE0001I 14.06.40 START OF DISPLAY FROM cat Example1.txt
        user3,blue:user1,green:user2,yellow
        END OF DISPLAY+

User:   ZFILE sort -R : -t , Example1.txt  

System: CSMP0097I 14.06.40 CPU-B SS-BSS  SSU-HPN  IS-01
        FILE0001I 14.06.40 START OF DISPLAY FROM sort -R : -t , Example1.txt
        user1,green:user2,yellow:user3,blue:
        END OF DISPLAY+
The following example sorts the Example2.txt file by using the second field of each record and ignoring non-alphanumeric characters and leading blank spaces. The -f parameter makes all character comparisons case-insensitive. The -d parameter specifies that only alphanumeric characters and blank spaces are used for comparison. However, the blank spaces are ignored because the -b parameter is specified.
User:   ZFILE cat Example2.txt

System: CSMP0097I 14.06.40 CPU-B SS-BSS SSU-HPN IS-01
        FILE0001I 14.06.40 START OF DISPLAY FROM cat Example2.txt
        4,  b
        3, !a
        1,   d
        8, C 
        END OF DISPLAY+

User:   ZFILE sort -d -f -b -t , -k 2,2 Example2.txt  

System: CSMP0097I 14.07.30 CPU-B SS-BSS  SSU-HPN  IS-01
        FILE0001I 14.07.30 START OF DISPLAY FROM sort -d -f -b -t , -k 2,2 Example...
        3, !a
        4,  b
        8, C
        1,   d
        END OF DISPLAY+
The following example sorts the Example3.txt file on 2 key fields, ignoring leading blank spaces in each field. The ZFILE sort command sorts the second field in descending order based on the third nonblank character, and then sorts the first field in ascending order.
User:   ZFILE cat Example3.txt

System: CSMP0097I 14.06.40 CPU-B SS-BSS SSU-HPN IS-01
        FILE0001I 14.06.40 START OF DISPLAY FROM cat Example3.txt
        4,  4.3
        2,  1.2
        3,  5.3
        6,  3.6
        3,  2.2
        2,  6.6
        END OF DISPLAY+

User:   ZFILE sort -t , -b -k 2.3,2.3r -k 1,1 Example3.txt  

System: CSMP0097I 14.07.57 CPU-B SS-BSS  SSU-HPN  IS-01
        FILE0001I 14.07.57 START OF DISPLAY FROM sort -t , -b -k 2.3,2.3r -k 1,1 E...
        2,  6.6
        6,  3.6
        3,  5.3
        4,  4.3
        2,  1.2
        3,  2.2
        END OF DISPLAY+
The following example redirects the standard output stream from the ZFILE du command as the input for the ZFILE sort command. The input will be sorted on the first field in descending order, treating this field as an integer value in each record.
User:   ZFILE du java | sort -nr -k 1,1  

System: CSMP0097I 13.47.50 CPU-B SS-BSS  SSU-HPN  IS-01
FILE0001I 13.47.50 START OF DISPLAY FROM du java | sort -nr -k 1,1
          6048.java
          6040.java/adbi
          6032.java/adbi/java
          6024.java/adbi/java/jar
          END OF DISPLAY+
The following example sorts the input1.txt file and stores the output in the output1.txt file. Then, the ZFILE sort command sorts the input2.txt file and pipes the output to be merged with the output1.txt file. Because the path is specified as a hyphen (-), the piped output from the preceding command is used as input for the current command. The final output is displayed to the standard output stream.
User:   ZFILE cat input1.txt

System: CSMP0097I 14.06.40 CPU-B SS-BSS SSU-HPN IS-01
        FILE0001I 14.06.40 START OF DISPLAY FROM cat input1.txt
        user1
        user4
        user2
        END OF DISPLAY+

User:   ZFILE cat input2.txt

System: CSMP0097I 14.06.40 CPU-B SS-BSS SSU-HPN IS-01
        FILE0001I 14.06.40 START OF DISPLAY FROM cat input2.txt
        user6
        user3
        user5
        END OF DISPLAY+

User:   ZFILE sort -o output1.txt input1.txt  

System: CSMP0097I 14.08.30 CPU-B SS-BSS  SSU-HPN  IS-01
        FILE0003I 14.08.30 sort -o out... COMPLETED SUCCESSFULLY.  NO OUTPUT TO DISPLAY+

User:   ZFILE sort input2.txt| sort –m output1.txt -  

System: CSMP0097I 09.47.10 CPU-B SS-BSS  SSU-HPN  IS-01
        FILE0001I 09.47.10 START OF DISPLAY FROM sort input2.txt | sort -m output1.t...
        user1
        user2
        user3
        user4
        user5
        user6
        END OF DISPLAY+