Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Jan 2002 19:04:41 +0100
From:      Robert Klein <RoKlein@roklein.de>
To:        adrian kok <adriankok2000@yahoo.com.hk>
Cc:        questions@FreeBSD.ORG
Subject:   Re: compare two files
Message-ID:  <E16WKb7-0007yZ-00@mrvdom02.kundenserver.de>
In-Reply-To: <20020131160655.42352.qmail@web21203.mail.yahoo.com>
References:  <20020131160655.42352.qmail@web21203.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help

> But the diff also outputs the data of fileB
> I only need fileA data whether it exists to fileB

If your files are lexically ordered, maybe comm(1) is the tool you 
look for.  E.g. 

comm -23 fileA fileB

If your files are not ordered, you can do so, using sort(1) and 
perhaps uniq(1), too.  For example:

cat fileA | sort | uniq >fileA.2
cat fileB | sort | uniq >fileB.2
comm -23 fileA.2 fileB.2 >diff-file

Please look up the manpages for those commands for further 
information.

Robert

>  --- Joel Dinel <dinjo@touchtunes.com> wrote: 
> > It
> > already exists, and it's called 'diff'.
> > man diff
> >
> > On Thu, Jan 31, 2002 at 11:50:13PM +0800, adrian kok wrote:
> > > 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

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?E16WKb7-0007yZ-00>