cmp command compares files byte by byte. Use the
-b option to see where the first difference occurs.
$ cat file1.txt hello how are you? $ cat file2.txt hello how art thee? $ cmp -b file1.txt file2.txt file1.txt file2.txt differ: byte 13, line 1 is 145 e 164 t
You may skip the first n bytes with the
-i option. Or to compare at most n bytes, use the
comm command allows you to see the lines common to two files. Simply pass in the file names of the two files you'd like to compare.
Let's first take a look at the two files we will use as an example:
$ cat file1.txt
Humphrey: Hey what's up? Jen: I'm fine how are you? Humphrey: I'm find as well. Jen: Great - want to watch a movie some time?
$ cat file2.txt
Humphrey: Top of the mornin' to ya - how art thee? Jen: I'm fine how are you? Humphrey: Thy is fine as one can be. Jen: Great - I'll see you around!
There are three columns of output that gets generated. The first column is indented by one tab, the second, two tabs, the third, three.
The first column shows the lines that are unique to the first file, while the second are those unique to the second file. The third line shows the line numbers that the files have in common.
$ comm file1.txt file2.txt
Humphrey: Hey what's up? Humphrey: Top of the mornin' to ya - how art thee? Jen: I'm fine how are you? Humphrey: I'm find as well. Humphrey: Thy is fine as one can be. Jen: Great - I'll see you around! Jen: Great - want to watch a movie some time?
To suppress any of these columns, use the
-n option where n specifies the column number.
$ comm -12 file1.txt file2.txt # Print only column 3 - lines that the files have in common
Jen: I'm fine how are you?
-i option for a case-insensitive comparison.
Relieve your stress, back, neck and sciatic pain through 1,782 acupuncture points for immediate neck pain relief. Made for lower, upper and mid chronic back pain treatment, and improves circulation, sleep, digestion and quality of life.$$ Check price
Command Line Kung Fu is packed with dozens of tips and practical real-world examples. You won't find theoretical examples in this book. The examples demonstrate how to solve actual problems. The tactics are easy to find, too. Each chapter covers a specific topic and groups related tips and examples together.$ Check price