5.4 Differences and Commonalities


8. Commands to learn:

dircmp (1)- compare directories (HPUX only)

cmp (1)   - perform a byte-by-byte comparison of two files

diff (1)  - display line-by-line differences between pairs of text files

comm (1)  - display lines in common and not in common, between two sorted lists

9. Examples

$ sort words | diff - words
$
$ cat aha
The purpose of this file is to provide text
that can be used to test various
features and commands of UNIX System V.
If necessary, more text will be added.
$ cat bah
The purpose of this file is to provide text
that can be, when necessary, used to test various
features and commands of UNIX System V.
$ diff aha bah
2c2
< that can be used to test various
---
> that can be, when necessary, used to test various
4d3
< If necessary, more text will be added.
$ cmp aha bah
aha bah differ: char 57, line 2
$ diff -e aha bah > changes
$ echo w >> changes
$ echo q >> changes
$ cp aha aha.old
$ more changes
4d
2c
that can be, when necessary, used to test various
.
w
q
$ ed aha < changes
157
136
$ more aha
The purpose of this file is to provide text
that can be, when necessary, used to test various
features and commands of UNIX System V.
$ more bah
The purpose of this file is to provide text
that can be, when necessary, used to test various
features and commands of UNIX System V.

$ comm bugs1 bugs2
		ants
		bees
beetles
	dragonflies
	earwigs
		grasshoppers
		roaches	

$ comm -12 bugs1 bugs2 > bugscom
$ cat bugscom
ants
bees
grasshoppers
roaches
$ cat newbugs
snakes
bees
mosquitos
$ sort newbugs | comm -13 bugs1 -
mosquitos
snakes

Questions? Robert Katz: rkatz@ned.highline.edu
Last Update July 23, 2002