Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 07 May 2011 03:13:39 +0200
From:      Rolf Nielsen <listreader@lazlarlyricon.com>
To:        Robert Bonomi <bonomi@mail.r-bonomi.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Comparing two lists
Message-ID:  <4DC49CC3.8000103@lazlarlyricon.com>
In-Reply-To: <201105070054.p470sgYR092690@mail.r-bonomi.com>
References:  <201105070054.p470sgYR092690@mail.r-bonomi.com>

next in thread | previous in thread | raw e-mail | index | archive | help
2011-05-07 02:54, Robert Bonomi skrev:
>>  From owner-freebsd-questions@freebsd.org  Fri May  6 19:27:54 2011
>> Date: Sat, 07 May 2011 02:09:26 +0200
>> From: Rolf Nielsen<listreader@lazlarlyricon.com>
>> To: FreeBSD<freebsd-questions@freebsd.org>
>> Subject: Comparing two lists
>>
>> Hello all,
>>
>> I have two text files, quite extensive ones. They have some lines in
>> common and some lines are unique to one of the files. The lines that do
>> exist in both files are not necessarily in the same location. Now I need
>> to compare the files and output a list of lines that exist in both
>> files. Is there a simple way to do this? diff? awk? sed? cmp? Or a
>> combination of two or more of them?
>
>
> If the files have only 'minor' differences -- i.e. no long runs of lines
> that are in only one fie -- *and* the common lines are  in the same order
> in each file, you can use diff(1), without any other shennigans.
>
> If the above is -not- true, and If you need _only_ the common lines, AND
> order is not important, then sort(1) both files, and use diff(1) on the
> two sorted versions.
>
>
> Beyond that it depends on what you mean by 'extensive' ones.  megabytes?
> Gigabytes? or what??
>
>
>

Some 10,000 to 20,000 lines each. I do need only the common lines. Order 
is not essential, but would make life easier. I've tried a little with 
uniq, as suggested by Polyptron, but I guess 3am is not quite the right 
time to do these things. Anyway, thanks.



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