From owner-freebsd-questions@FreeBSD.ORG Fri Oct 14 16:27:46 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C81FF16A41F for ; Fri, 14 Oct 2005 16:27:46 +0000 (GMT) (envelope-from pauls@utdallas.edu) Received: from smtp1.utdallas.edu (smtp1.utdallas.edu [129.110.10.12]) by mx1.FreeBSD.org (Postfix) with ESMTP id 812FC43D48 for ; Fri, 14 Oct 2005 16:27:46 +0000 (GMT) (envelope-from pauls@utdallas.edu) Received: from utd59514.utdallas.edu (utd59514.utdallas.edu [129.110.3.28]) by smtp1.utdallas.edu (Postfix) with ESMTP id 10D163891F7 for ; Fri, 14 Oct 2005 11:27:46 -0500 (CDT) Date: Fri, 14 Oct 2005 11:27:46 -0500 From: Paul Schmehl To: FreeBSD Questions Message-ID: <72CE9870C77DFB8443C76023@utd59514.utdallas.edu> In-Reply-To: <434FD118.60109@mykitchentable.net> References: <434EE80D.2010103@mykitchentable.net> <0D55CDDCD0D6445B3FF1FA6B@Paul-Schmehls-Computer.local> <434FD118.60109@mykitchentable.net> X-Mailer: Mulberry/3.1.6 (Linux/x86) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: Re: sh Scripting - String Manipulation 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: Fri, 14 Oct 2005 16:27:46 -0000 --On Friday, October 14, 2005 08:39:04 -0700 Drew Tomlinson wrote: > > > That's a good idea (and something else I never thought of) if I wanted > all the files, not just the *.jpg files. And as I'll explain below, I > intend to expand this script to work with additional directories where I > might just want the *.mp3 or the just the *.avi, *.mpg, etc. My thought > was to build a script and run it through cron to keep the symlinks > updated. > OK. Then I think you're going about it the wrong way. This would accomplish what you want without having to do any string manipulation, and without having to generate a list of files. The for loop does all that for you. for files in /my/dir/for/files/*.jpg do NEWFILES=`$files | cut -d'/' -f 6` ln -s $files /new/dir/for/pics/$NEWFILES done Before you put the symlink line in the script, you'll want to echo $NEWFILES so you can make sure you're cutting at the right place. (Practice on the commandline so you can see what cut is doing.) Paul Schmehl (pauls@utdallas.edu) Adjunct Information Security Officer University of Texas at Dallas AVIEN Founding Member http://www.utdallas.edu/ir/security/