Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr3889 :: comm - compare two sorted files line by line

A great tool to quickly find the differences between two files

<< First, < Previous, , Latest >>

Thumbnail of Ken Fallon
Hosted by Ken Fallon on Thursday, 2023-06-29 is flagged as Clean and is released under a CC-BY-SA license.
comm, compare, coreutils. 2.
The show is available on the Internet Archive at: https://archive.org/details/hpr3889

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:03:15

general.

From the man page "comm - compare two sorted files line by line"

It's part of the core utils package and you can install it using dnf install coreutils on RPM distros, or apt install coreutils on Debian based ones.

[host@hpr]$ man comm

COMM(1)                               User Commands                              COMM(1)

NAME
       comm - compare two sorted files line by line

SYNOPSIS
       comm [OPTION]... FILE1 FILE2

DESCRIPTION
       Compare sorted files FILE1 and FILE2 line by line.

       When FILE1 or FILE2 (not both) is -, read standard input.

       With no options, produce three-column output.  Column one contains lines unique to FILE1,
       column two contains lines unique to FILE2, and column three contains lines common to both
       files.

       -1     suppress column 1 (lines unique to FILE1)

       -2     suppress column 2 (lines unique to FILE2)

       -3     suppress column 3 (lines that appear in both files)

       --check-order
              check that the input is correctly sorted, even if all input lines are pairable

       --nocheck-order
              do not check that the input is correctly sorted

       --output-delimiter=STR
              separate columns with STR

       --total
              output a summary

       -z, --zero-terminated
              line delimiter is NUL, not newline

       --help display this help and exit

       --version
              output version information and exit

       Note, comparisons honor the rules specified by 'LC_COLLATE'.

EXAMPLES
       comm -12 file1 file2
              Print only lines present in both file1 and file2.

       comm -3 file1 file2
              Print lines in file1 not in file2, and vice versa.

AUTHOR
       Written by Richard M. Stallman and David MacKenzie.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report any translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright © 2022 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later
       <https://gnu.org/licenses/gpl.html>.  This is free software: you are free to change and
       redistribute it.  There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       join(1), uniq(1)

       Full documentation <https://www.gnu.org/software/coreutils/comm>
       or available locally via: info '(coreutils) comm invocation'

GNU coreutils 9.1

I always find that confusing, so for me it's a lot easier to see what is going on by creating some example files.

First let's create some test files by echoing the number 1 and the number 2 into a file called 1and2.txt

[host@hpr]$ echo "1" > 1and2.txt
[host@hpr]$ echo "2" >> 1and2.txt

And let's create another one with the value 2 and 3 and we'll call it 2and3.txt

[host@hpr]$ echo "2" > 2and3.txt
[host@hpr]$ echo "3" >> 2and3.txt

Then we can see what each command does using these examples.

[host@hpr]$ comm -1 -2 1and2.txt 2and3.txt
2
[host@hpr]$ comm -1 -3 1and2.txt 2and3.txt
3
[host@hpr]$ comm -2 -3 1and2.txt 2and3.txt
1

Comments

Subscribe to the comments RSS feed.

Comment #1 posted on 2023-07-08 14:40:16 by Reto

KDirStat is dead, long live QDirStat!

Hi Ken,

Could it be that you mixed up kdiff3 https://apps.kde.org/kdiff3/ with KDirStat, while we were talking in the "Community News for June" show?

_____
QDirStat is based on that same code from the original KDE 3 KDirStat of 2006. It's an 80% rewrite using a lot of newer Qt technologies. And there was a lot of cleaning up that old code base that had been long overdue.

_____
If so, QDirStat is also interesting, it comes with nice features like
Package manager support:
- Show what software package a system file belongs to.
- Packages view showing disk usage of installed software packages and their individual files.
- Unpackaged files view showing what files in system directories do not belong to any installed software package.

And is just an apt install away :-)

However, you helped me anyway!
Because, while in KDE Dolphin's kdiff3 integration can only compare two files in the same folder, I can use it in the terminal with paths to the files like:

kdiff3 /home/reto/abc.txt /media/usb/abc.txt

Br,
Reto

Comment #2 posted on 2023-07-12 06:08:21 by Ken Fallon

QDirstat is nice but I meant kdiff3

Nice tip on QDirstat


But I meant kdiff3 /path/to/old /path/to/new

Perhaps I need to do a show about this...

.... hold on - I see what you did there.

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
Who is the host of this show?
What does HPR mean to you?