From owner-freebsd-questions@FreeBSD.ORG Tue Aug 17 21:29:38 2010 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 167EA106564A for ; Tue, 17 Aug 2010 21:29:38 +0000 (UTC) (envelope-from vogelke@hcst.net) Received: from beta.hcst.com (beta.hcst.com [192.52.183.241]) by mx1.freebsd.org (Postfix) with ESMTP id CD41D8FC0A for ; Tue, 17 Aug 2010 21:29:37 +0000 (UTC) Received: from beta.hcst.com (localhost [127.0.0.1]) by beta.hcst.com (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id o7HLBmoS002496 for ; Tue, 17 Aug 2010 17:11:48 -0400 Received: (from vogelke@localhost) by beta.hcst.com (8.14.3/8.14.3/Submit) id o7HLBlRw002495; Tue, 17 Aug 2010 17:11:47 -0400 Received: by kev.msw.wpafb.af.mil (Postfix, from userid 32768) id B7FFFBF39; Tue, 17 Aug 2010 17:09:39 -0400 (EDT) To: freebsd-questions@freebsd.org In-reply-to: message from Drew Tomlinson on Tue, 17 Aug 2010 07:47:25 -0700 Organization: Array Infotech X-Disclaimer: I don't speak for the USAF or Array Infotech. X-GPG-ID: 1024D/711752A0 2006-06-27 Karl Vogel X-GPG-Fingerprint: 56EB 6DBF 4224 C953 F417 CC99 4C7C 7D46 7117 52A0 Message-Id: <20100817210939.B7FFFBF39@kev.msw.wpafb.af.mil> Date: Tue, 17 Aug 2010 17:09:39 -0400 (EDT) From: vogelke+unix@pobox.com (Karl Vogel) Subject: Re: Bash Script Help - File Names With Spaces X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: vogelke+unix@pobox.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Aug 2010 21:29:38 -0000 >> On Tue, 17 Aug 2010 07:47:25 -0700, >> Drew Tomlinson said: D> Then I attempt to use 'basename' to extract the file name to a variable D> which I can later pass to 'ln'. This seems to work: D> basename "/archive/Multimedia/Audio/Music/Billboard Top USA D> Singles/1980-028 Kenny Loggins - This Is It.mp3" This is a subset of a larger problem: getting the last field from a set of delimited records which may not all have the same number of fields. I've used this when I needed basenames for ~500,000 files: find . regex-or-print-or-whatever | rev | cut -f1 -d/ | rev For dirnames: find . regex-or-print-or-whatever | rev | cut -f2- -d/ | rev | sort -u -- Karl Vogel I don't speak for the USAF or my company When I'm feeling down, I like to whistle. It makes the neighbor's dog run to the end of his chain and gag himself. --unknown