Skip site navigation (1)Skip section navigation (2)
Date:      31 Jan 2002 16:11:44 +0000
From:      Wayne Pascoe <freebsd@molemanarmy.com>
To:        adrian kok <adriankok2000@yahoo.com.hk>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: compare two files
Message-ID:  <m2u1t2sdof.fsf@set.ehsbrann.com>
In-Reply-To: <20020131155013.82668.qmail@web21209.mail.yahoo.com>
References:  <20020131155013.82668.qmail@web21209.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
adrian kok <adriankok2000@yahoo.com.hk> writes:

> I would like to know how to write script or program to
> compare two file
> 
> two files: file1 and file2
> 
> check data of file1 whether exists in file2
> 
> if not
> 
> write this data in file1 or output to file
> 
> #!/bin/sh 
> $lista=fopen("a.txt", "r"); 
> $listb=fopen("b.txt", "r"); 
> 
> while(!feof($lista)) { 
> $dmbuffer = fgets ($lista); 
> grep $dmbuffer $listb > diff; 
> } 

I think that using diff might do what you want.

diff file1 file2 
this will print the lines in each file that differ to standard
output. This can be redirected to a file by doing
diff file1 file2 > differences


HTH

-- 
- Wayne Pascoe
                                 | Everything to excess. To enjoy the 
freebsd@molemanarmy.com          | flavor of life, take big bites. Moderation 
http://www.molemanarmy.com       | is for monks. - Robert Heinlein
                                 | 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?m2u1t2sdof.fsf>