shell

comm, common lines in two files

Given two ordered files, like

$ cat foo
abbreviation
carnivore
meal
topology

and

$ cat bar
aristide
meal
nap
scout
topology
zero

comm prints, in succession and in a three-column format, the lines corresponding exclusively to the first file (first column), exclusively to the second file (second column) and to both of them (third column). Thus,

$ comm foo bar
abbreviation
        aristide
carnivore
                meal
        nap
        scout
                topology
        zero

CL options are -f (fold case in comparison) and any (or several) of -1, -2, -3, which suppresses the output of column 1, 2 and/or 3. So, in above’s example,

$ comm -2 foo bar
abbreviation
carnivore
        meal
        topology

For example, if you want to get rid of some words in your dictionary, you may do

$ comm -13 - foo > foo.without.topology
topology
^d
$ cat foo.without.topology
abbreviation
carnivore
meal

More useful than one can think at first.

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*Required Fields