APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2003/11/19 diff

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.




Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Tony Lawrence



Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

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





Actually I made up the term "object-oriented", and I can tell you I did not have C++ in mind. (Alan Kay)





This post tagged: