From owner-freebsd-questions@FreeBSD.ORG Tue Dec 16 19:39:17 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7EA7931B for ; Tue, 16 Dec 2014 19:39:17 +0000 (UTC) Received: from mx02.qsc.de (mx02.qsc.de [213.148.130.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3D186D0 for ; Tue, 16 Dec 2014 19:39:16 +0000 (UTC) Received: from r56.edvax.de (port-92-195-93-98.dynamic.qsc.de [92.195.93.98]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx02.qsc.de (Postfix) with ESMTPS id 1E21A24CFF; Tue, 16 Dec 2014 20:39:07 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id sBGJd759002128; Tue, 16 Dec 2014 20:39:07 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Tue, 16 Dec 2014 20:39:07 +0100 From: Polytropon To: jungle Boogie Subject: Re: Perl rename utility assistance Message-Id: <20141216203907.6dddfe9e.freebsd@edvax.de> In-Reply-To: References: <54907B51.1060807@gmail.com> <20141216184002.GA26978@neutralgood.org> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: "freebsd-questions@freebsd.org" , kpneal@pobox.com 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: Tue, 16 Dec 2014 19:39:17 -0000 On Tue, 16 Dec 2014 11:20:50 -0800, jungle Boogie wrote: > Hello Kevin, > On 16 December 2014 at 10:40, wrote: > > A little bit of quick scripting should do this without needing a > > rename or whatever program. > > > > #! /bin/sh > > > > oname="$1" > > nname=$(echo "$oname" | sed 's/_/ /') > > > > set -x > > mv "$oname" "$nname" > > What if you have a directory full of files you want to update? See: #!/bin/sh set -x for oname in *.*; do nname=`echo "${oname}" | sed 's/_/ /'` mv "${oname]" "${nname}" done Not that it is _wrong_ to deal with file name iteration that way. Take my example as "works in many cases, but you shouldn't do it that way". Instead, go ahead and read: http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html http://www.dwheeler.com/essays/filenames-in-shell.html Then return to do it better. ;-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...