1833006 Members
3456 Online
110048 Solutions
New Discussion

Diff

 
SOLVED
Go to solution
Vanquish
Occasional Advisor

Diff

Hi
I want to do a diff between two files and want output that lines not present in second file.

Ex diff file1 file2
output only lines present in file1 and not file2.
Thanks
9 REPLIES 9
Charlie Rubeor
Frequent Advisor

Re: Diff

Try the following

comm -1 file1 file2
Sanjay_6
Honored Contributor

Re: Diff

Hi,

Try

sdiff -s file1 file2

Do "man sdiff" for more details / help.

Hope this helps.

Regds
Scott Palmer_1
Trusted Contributor
Solution

Re: Diff

on hpux it is comm -23 file1 file2
Regards

Scott
Shane Travis
Frequent Advisor

Re: Diff

Charlie almost has it right. Comm shows three columns:

Col1 = lines that appear ONLY in file1
Col2 = lines that appear ONLY in file2
col3 = lines that appear in both files

To show only column one, you have to suppress the other two columns, so what you want is:

comm -23 file1 file3

Victor Fridyev
Honored Contributor

Re: Diff

Try this:

cat f1 f2 |sort -u >tmpf
cat f2 tmpf |sort |uniq -u
cat f1 tmpf |sort |uniq -u

Entities are not to be multiplied beyond necessity - RTFM
Juergen Tappe
Valued Contributor

Re: Diff

That should do it as well :

diff file1 file2 | grep "^< " | cut -c3-
Working together
Mike Stroyan
Honored Contributor

Re: Diff

Watch out for comm's prerequisite.
The input files need to be sorted.
You could sort into temporary files before using comm.

The suggestion using uniq would be broken by lines that are duplicated within one file.
H.Merijn Brand (procura
Honored Contributor

Re: Diff

If you would like to get some more answers and some explanations, I bet you will find this thread very interesting

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=388167

It went on after the question was answered, just as in your case

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Dani Seely
Valued Contributor

Re: Diff

Don't know if you are still having problems or not but thought I'd throw my two cents in. I have needed to do this same thing myself and find the "sdiff" command the easiest to work with. The sdiff command allows you to find differences between two files. The options are VERY useful so I *HIGHLY* suggest you take a few minutes and look at the man page for sdiff. There are some neat options like:
-s allows you to suppress the lines common in both files so all you see are the differences, and
-w allows you to set the width of each line, which is VERY useful if you have long lines.

Suggest you try the following:
# sdiff -s -w132 file1 file2 |grep " < "

The identifier of unique findings in file1 is noted by the < sign with whitespace around it, so use spaces not tabs in front of and after the < sign.

Hope this helps, it works great for me.
Together We Stand!