From owner-freebsd-questions@FreeBSD.ORG Thu Nov 6 19:20:38 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 94EEFD13 for ; Thu, 6 Nov 2014 19:20:38 +0000 (UTC) Received: from stangl.us (stangl.us [66.93.193.95]) by mx1.freebsd.org (Postfix) with ESMTP id 6063EB5A for ; Thu, 6 Nov 2014 19:20:38 +0000 (UTC) Received: from scout.stangl.us (localhost [127.0.0.1]) by scout.stangl.us (Postfix) with ESMTP id A0A4817024 for ; Thu, 6 Nov 2014 13:20:37 -0600 (CST) X-Virus-Scanned: amavisd-new at stangl.us Received: from stangl.us ([127.0.0.1]) by scout.stangl.us (scout.stangl.us [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1-OiB1vrZSyP for ; Thu, 6 Nov 2014 13:20:37 -0600 (CST) Received: by scout.stangl.us (Postfix, from userid 1001) id 362AC17022; Thu, 6 Nov 2014 13:20:37 -0600 (CST) Date: Thu, 6 Nov 2014 13:20:37 -0600 From: Alex Stangl To: freebsd-questions@freebsd.org Subject: Re: uniq(1) on last field Message-ID: <20141106192037.GA15248@scout.stangl.us> Mail-Followup-To: freebsd-questions@freebsd.org References: <20141106110319.eb34eaa069a4881824072010@3dresearch.com> <20141106184306.GA14996@scout.stangl.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20141106184306.GA14996@scout.stangl.us> User-Agent: Mutt/1.5.23 (2014-03-12) 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 19:20:38 -0000 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