From owner-freebsd-questions@FreeBSD.ORG Fri Nov 7 05:16:25 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 C636B5D6 for ; Fri, 7 Nov 2014 05:16:25 +0000 (UTC) Received: from smtpb.telissant.net (smtpb.telissant.net [199.233.230.156]) by mx1.freebsd.org (Postfix) with ESMTP id 985B992F for ; Fri, 7 Nov 2014 05:16:25 +0000 (UTC) Received: from barrida.3dresearch.com (localhost [127.0.0.1]) by smtpb.telissant.net (Postfix) with ESMTP id B45E227330 for ; Fri, 7 Nov 2014 00:16:23 -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 c7E7sQV6Cmsc for ; Fri, 7 Nov 2014 00:15:58 -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 655A52731E for ; Fri, 7 Nov 2014 00:15:58 -0500 (EST) Received: from doncurzio.3dresearch.com (localhost [127.0.0.1]) by doncurzio.3dresearch.com (Postfix) with SMTP id C3643A1E2C for ; Fri, 7 Nov 2014 00:15:57 -0500 (EST) Date: Fri, 7 Nov 2014 00:15:36 -0500 From: Janos Dohanics To: FreeBSD Questions Subject: Re: uniq(1) on last field Message-Id: <20141107001536.4facb64ccb4606e919d0c780@3dresearch.com> In-Reply-To: <20141106192037.GA15248@scout.stangl.us> References: <20141106110319.eb34eaa069a4881824072010@3dresearch.com> <20141106184306.GA14996@scout.stangl.us> <20141106192037.GA15248@scout.stangl.us> X-Mailer: Sylpheed 3.3.0 (GTK+ 2.24.19; amd64-portbld-freebsd9.1) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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: Fri, 07 Nov 2014 05:16:25 -0000 On Thu, 6 Nov 2014 13:20:37 -0600 Alex Stangl wrote: > On Thu, Nov 06, 2014 at 12:43:06PM -0600, Alex Stangl wrote: > > On Thu, Nov 06, 2014 at 11:03:19AM -0500, Janos Dohanics wrote: > > > Would you please help with a shell scripting problem. I have a > > > samba audit log file which after some parsing has entries like > > > this: > > > > > > Nov 5 15:07:10 testuser 10.10.10.72 pluto pwrite ok > > > COMMON/Solidworks Parts & Assemblies/CDE - Beck/Tube Baffle > > > Coalescer Model/~$40in OD Shell.SLDPRT > > > > > > I would like to use uniq(1) on the file name, which is of course > > > the last field if / is used as field separator. > > > > $ awk -F'/' '{printf "%s%s%s\n", $NF, "/", $0}' yourfile.txt | sort > > -k '1,1' -u -t'/' | cut -f2- -d'/' > > Or, even shorter, > > $ awk -F'/' '{printf "%s/%s\n", $NF, $0}' yourfile.txt | sort -k > '1,1' -u -t'/' | cut -f2- -d'/' > > > Alex Alex, works perfectly, thank you. Thank you everyone for your suggestions. -- Janos Dohanics