From owner-freebsd-questions@FreeBSD.ORG Thu Nov 6 18:30:30 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8FCCF199 for ; Thu, 6 Nov 2014 18:30:30 +0000 (UTC) Received: from smtpb.telissant.net (smtpb.telissant.net [199.233.230.156]) by mx1.freebsd.org (Postfix) with ESMTP id 5F5CE639 for ; Thu, 6 Nov 2014 18:30:29 +0000 (UTC) Received: from barrida.3dresearch.com (localhost [127.0.0.1]) by smtpb.telissant.net (Postfix) with ESMTP id A838827330 for ; Thu, 6 Nov 2014 13:30:28 -0500 (EST) X-Virus-Scanned: amavisd-new at telissant.net Received: from smtpb.telissant.net ([127.0.0.1]) by barrida.3dresearch.com (barrida.3dresearch.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cTrsydDYvFov for ; Thu, 6 Nov 2014 13:30:12 -0500 (EST) Received: from doncurzio.3dresearch.com (pool-71-112-0-222.pitbpa.east.verizon.net [71.112.0.222]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtpb.telissant.net (Postfix) with ESMTPSA id AE6D927309 for ; Thu, 6 Nov 2014 13:30:12 -0500 (EST) Received: from doncurzio.3dresearch.com (localhost [127.0.0.1]) by doncurzio.3dresearch.com (Postfix) with SMTP id 16E55A1E2C for ; Thu, 6 Nov 2014 13:30:12 -0500 (EST) Date: Thu, 6 Nov 2014 13:29:41 -0500 From: Janos Dohanics To: FreeBSD Questions Subject: Re: uniq(1) on last field Message-Id: <20141106132941.cc33fc02635648cf537885a1@3dresearch.com> In-Reply-To: <33AF1AA1-9768-4D65-86A7-88A307AEFA5C@boosten.org> References: <20141106110319.eb34eaa069a4881824072010@3dresearch.com> <33AF1AA1-9768-4D65-86A7-88A307AEFA5C@boosten.org> X-Mailer: Sylpheed 3.3.0 (GTK+ 2.24.19; amd64-portbld-freebsd9.1) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Nov 2014 18:30:30 -0000 On Thu, 6 Nov 2014 18:32:50 +0100 Peter Boosten wrote: > > > On 6 nov. 2014, at 17:42, Peter Boosten wrote: > > > > > >> > >> > >> I would like to use uniq(1) on the file name, which is of course > >> the last field if / is used as field separator. > >> > >> How can I tell uniq(1) the "last field" if I have variable number > >> of fields? > > > > > > sort -u might be a better option > > > > Ah, I missed the ‘variable number of fields’… > > What is it you’re trying to show? Since the line in itself always is > unique. If you only want to show the file name, you could use awk > ‘{print $NF}’ to show the last field, end pipe that through uniq. > > so: > > awk ‘{print $NF}’ file | uniq (-c if you want to count them) > > I don’t think either uniq nor sort have any notion of 'last field’ in > a variable field situation. > > -- > Peter Boosten I would like to output the entire line as it is in my original post, and get rid of the repetition of the same file names. So the pseudo code would be something like: cat file | uniq -f [n-1] where n = awk -F "/" '{print NF}' Is this possible to do with a one-liner? -- Janos Dohanics