From owner-freebsd-questions Thu Jan 31 8:11:18 2002 Delivered-To: freebsd-questions@freebsd.org Received: from clientmail.ehsrealtime.com (eris.ehsrealtime.com [213.52.146.130]) by hub.freebsd.org (Postfix) with ESMTP id B4ACD37B416 for ; Thu, 31 Jan 2002 08:11:13 -0800 (PST) Received: from set.ehsrealtime.com ([213.52.146.197]) by clientmail.ehsrealtime.com with esmtp (Exim 3.33 #2) id 16WJRV-000GNz-01; Thu, 31 Jan 2002 15:48:05 +0000 Received: from waynep by set.ehsrealtime.com with local (Exim 3.34 #3) id 16WJoP-0000Kd-00; Thu, 31 Jan 2002 16:11:45 +0000 From: Wayne Pascoe To: adrian kok Cc: freebsd-questions@FreeBSD.ORG Subject: Re: compare two files References: <20020131155013.82668.qmail@web21209.mail.yahoo.com> Date: 31 Jan 2002 16:11:44 +0000 In-Reply-To: <20020131155013.82668.qmail@web21209.mail.yahoo.com> Message-ID: Lines: 38 User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.5 (bamboo) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG adrian kok 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