File comparison, and patch file creator.
Let's say we have two files, t1 and t2
(t1) abcdefg abcdefg abcdefg abcdefg (t2) abcdefg defghij abcdefg abcdefg abcdefg
A simple "diff t1 t2" produces:
1a2 > defghij
The actual output may not be important to you if all you want to know is if they are different. If they are, $? will be 1 after this, and 0 otherwise. So:
cp t1 t3 diff t1 t3 > /dev/null || echo "t1 and t3 are different" diff t1 t3 > /dev/null && echo "t1 and t3 are not different" diff t1 t2 > /dev/null || echo "t1 and t2 are different" diff t1 t2 > /dev/null && echo "t1 and t2 are not different"
works as expected.
When looking at a diff file, simply remember that everything you see is relative to the FIRST file argument, and that "<" is taking away from it, while ">" is adding to it.
However, there are other arguments you can give to diff that will produce different output. "diff -e" puts out actual instructions you could feed to "ed" to change file1 into file2. "diff -c" produces output that can be fed to "patch" for the same purpose (use the older version of the file as the first argument after -c).
Got something to add? Send me email.
More Articles by Tony Lawrence © 2011-07-05 Tony Lawrence
Just because they've sold you an IP based phone system doesn't mean they know anything about IP, does it? (Tony Lawrence)
Printer Friendly Version
diff Copyright © November 2003 Tony Lawrence
Have you tried Searching this site?
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.
Contact us
Printer Friendly Version