From owner-freebsd-questions@FreeBSD.ORG Sat May 7 03:11:34 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 3E8AD1065672 for ; Sat, 7 May 2011 03:11:34 +0000 (UTC) (envelope-from yuri.pankov@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id AA99F8FC13 for ; Sat, 7 May 2011 03:11:33 +0000 (UTC) Received: by bwz12 with SMTP id 12so4283226bwz.13 for ; Fri, 06 May 2011 20:11:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:x-authentication-warning:date:from:to:cc :subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent; bh=JK2BH22/Ui/Is1ZuXehRmaPZfJprChPtT+jbZD0o6tw=; b=m/Lk4cxbTVaMU8kIHDaVMhPJR2u/RYSv15xhltFgaBhgQJ/0WpMGzNXifHj21lhoPz M1EO9dzs1b4VtFef/gD2eThpomNpz4LMmLRAgXWdRMEWPObkF2vAbXaWNmPk+VQrFe9u LqpT6ChLSIjlak/cz0bewvXpfl+kUoYocjzEs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=x-authentication-warning:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent; b=WXhwG8MahUV9wfKg3hKQLf8WrS1MZCWre5NzH1IvWbscjP7moK/3rZRBKJHoLO7+c+ 2PrsORmyE7FzUdS93zl49iPZhl+ZYhruxTRqJ+0TRmFboC9BE5wFs9XyRPHt5NrP7p0e ydBmqwKW3WfZAAFHhDGTBjCDU2DAtjmRGgdGA= Received: by 10.204.84.27 with SMTP id h27mr610208bkl.158.1304737892394; Fri, 06 May 2011 20:11:32 -0700 (PDT) Received: from procyon.xvoid.org ([213.132.76.142]) by mx.google.com with ESMTPS id 16sm2347122bkm.6.2011.05.06.20.11.30 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 06 May 2011 20:11:31 -0700 (PDT) Received: from procyon.xvoid.org (yuri@procyon.xvoid.org [IPv6:::1]) by procyon.xvoid.org (8.14.4/8.14.4) with ESMTP id p473BSvF014027; Sat, 7 May 2011 07:11:28 +0400 (MSD) (envelope-from yuri.pankov@gmail.com) Received: (from yuri@localhost) by procyon.xvoid.org (8.14.4/8.14.4/Submit) id p473BSqo014026; Sat, 7 May 2011 07:11:28 +0400 (MSD) (envelope-from yuri.pankov@gmail.com) X-Authentication-Warning: procyon.xvoid.org: yuri set sender to yuri.pankov@gmail.com using -f Date: Sat, 7 May 2011 07:11:28 +0400 From: Yuri Pankov To: Rolf Nielsen Message-ID: <20110507031128.GC1222@procyon.xvoid.org> References: <4DC48DB6.8030907@lazlarlyricon.com> <4DC4AD2C.30307@lazlarlyricon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4DC4AD2C.30307@lazlarlyricon.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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 03:11:34 -0000 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 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. HTH, Yuri