[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 1

comm Command

Purpose

Selects or rejects lines common to two sorted files.

Syntax

comm [  -1  -2  -3 ] File1 File2

Description

Note: If you specify - (minus) for one of the file names, the comm command reads standard input.

The comm command reads the File1 and File2 parameters and writes, by default, a three-column output to standard output. The columns consist of:

Both File1 and File2 should be sorted according to the collating sequence specified by the current National Language environment.

Flags

-1 Suppresses the display of the first column (lines in File1).
-2 Suppresses the display of the second column (lines in File2).
-3 Suppresses the display of the third column (lines common to File1 and File2).

Exit Status

This command returns the following exit values:

0 All input files were output successfully.
>0 An error occurred.

Examples

  1. To display the lines unique to each file and common to both, enter:

    comm things.to.do things.done

    If the files things.to.do and things.done contain the following lists:

    things.to.do
     
    buy soap
    groceries
    luncheon
    meeting at 3
    system update
    tech. review
     
    things.done
     
    2nd revision
    interview
    luncheon
    system update
    tech. review
    weekly report

    then the comm command displays:

           2nd revision
    buy soap
    groceries
           interview
                   luncheon
    meeting at 3
                   system update
                   tech. review
           weekly report

    The first column contains the lines found only in things.to.do. The second column, indented with a tab character, lists the lines found only in things.done. The third column, indented with two tabs, lists the lines common to both.

  2. To display the lines that appear in only one file, enter:

    comm -23 things.to.do things.done

    This suppresses the second and third columns of the comm command listing. If the files are the same as in Example 1, then the following is displayed:

    buy soap
    groceries
    meeting at 3

File

/usr/bin/comm Contains the comm command.

Related Information

The cmp command, diff command, sdiff command, sort command, uniq command.

The environment file.

Understanding Locale in AIX 5L Version 5.2 System Management Concepts: Operating System and Devices.

National Language Support Overview for Programming in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]