From owner-freebsd-questions@FreeBSD.ORG Sat May 7 11:00:18 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0D0E41065672 for ; Sat, 7 May 2011 11:00:17 +0000 (UTC) (envelope-from listreader@lazlarlyricon.com) Received: from mailgw7.surf-town.net (mail6.surf-town.net [212.97.132.46]) by mx1.freebsd.org (Postfix) with ESMTP id A41AF8FC14 for ; Sat, 7 May 2011 11:00:17 +0000 (UTC) Received: by mailgw7.surf-town.net (Postfix, from userid 65534) id 86A80EBD7B; Sat, 7 May 2011 13:00:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mailgw7.surf-town.net (Postfix) with ESMTP id 60378EBD7B; Sat, 7 May 2011 13:00:16 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mailgw7.surf-town.net X-Spam-Flag: NO X-Spam-Score: -1.44 X-Spam-Level: X-Spam-Status: No, score=-1.44 tagged_above=-999 required=7 tests=[ALL_TRUSTED=-1.44] Received: from mailgw7.surf-town.net ([127.0.0.1]) by localhost (mailgw7.surf-town.net [127.0.0.1]) (amavisd-new, port 10024) with LMTP id n8ZW7eW8C6T2; Sat, 7 May 2011 13:00:11 +0200 (CEST) Received: from lazlar.kicks-ass.net (c-0987e355.09-42-6e6b7010.cust.bredbandsbolaget.se [85.227.135.9]) by mailgw7.surf-town.net (Postfix) with ESMTPA id AFA82EBE73; Sat, 7 May 2011 13:00:09 +0200 (CEST) Message-ID: <4DC52638.7040801@lazlarlyricon.com> Date: Sat, 07 May 2011 13:00:08 +0200 From: Rolf Nielsen User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; sv-SE; rv:1.9.2.17) Gecko/20110502 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: Yuri Pankov References: <4DC48DB6.8030907@lazlarlyricon.com> <4DC4AD2C.30307@lazlarlyricon.com> <20110507031128.GC1222@procyon.xvoid.org> In-Reply-To: <20110507031128.GC1222@procyon.xvoid.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Subject: Re: Comparing two lists [SOLVED (at least it looks like that)] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 May 2011 11:00:18 -0000 2011-05-07 05:11, Yuri Pankov skrev: > On Sat, May 07, 2011 at 04:23:40AM +0200, Rolf Nielsen wrote: >> 2011-05-07 02:09, Rolf Nielsen skrev: >>> 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? >>> >>> TIA, >>> >>> Rolf >> >> sort file1 file2 | uniq -d > > I very seriously doubt that this line does what you want... > > $ printf "a\na\na\nb\n"> file1; printf "c\nc\nb\n"> file2; sort file1 file2 | uniq -d > a > b > c Ok. I do understand the problem. Though the files I have do not have any duplicate lines, so that possibility didn't even cross my mind. > > > Try this instead (probably bloated): > > sort< file1 | uniq | tr -s '\n' '\0' | xargs -0 -I % grep -Fx % file2 | sort | uniq > > There is comm(1), of course, but it expects files to be already sorted. The files are sorted, so comm would work. Several people have already suggested comm, though I haven't tried it, as combining sort and uniq does what I want with my specific files. > > > HTH, > Yuri >