zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: Timothy J Luoma <luomat+Lists/Zsh/users@luomat.peak.org>,
	zsh-users@math.gatech.edu (Zsh users list)
Subject: Re: help with 'rename' function
Date: Fri, 12 Jun 1998 11:09:12 +0200	[thread overview]
Message-ID: <199806120909.LAA21384@hydra.ifh.de> (raw)
In-Reply-To: "Timothy J Luoma"'s message of "Fri, 12 Jun 1998 04:15:57 MST." <199806120816.EAA22173@luomat.peak.org>

Timothy J Luoma wrote:
> I used to have a binary that did this, but I've lost it.
> 
> What it did was simple: it changed extensions of filenames.

It's perennially annoying UNIX doesn't have this.  On the other hand,
if it did it would probably be so inscrutable as to be almost useless.

If you want a proper programme, search the archives for mmv.  There's
also a widely distributed perl script called rename which allows perl
operations on the file name, e.g. 's/\.this$/.that/' in this case.
(I can mail my version.)

If you want a shell function, it's appended...

> For example, say you have a bunch of files which ended with .THIS and you  
> wanted to change them to end with .THAT
> 
> You would do
> 
> 	rename *.THIS THIS=THAT

...the difference is it was easier to stick the THIS=THAT argument
first rather than last.  Everything's done by the shell, so it's
a bit simpler.  It's limited to suffixes as written.  Note the -f
if you want to overwrite an existing file.


# rename.zsh
local force
[[ $1 = -f ]] && shift && force=1

if [[ $# -lt 2 || $1 != *=* ]]; then
  print "Usage:  $0 oldsuf=newsuf file ..." 2>&1
fi

local old new ofile nfile
old=${1%=*}
new=${1#*=}

shift

for ofile in $*; do
  nfile=${ofile%$old}$new
  if [[ -f $nfile && $force != 1 ]]; then
    print "$nfile already exists" 2>&1
  else
    mv $ofile $nfile
  fi
done
# end

-- 
Peter Stephenson <pws@ifh.de>       Tel: +39 50 844536
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


  reply	other threads:[~1998-06-12  9:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-06-12  8:15 Timothy J Luoma
1998-06-12  9:09 ` Peter Stephenson [this message]
1998-06-14 20:05   ` Paul Lew
1998-06-12  9:14 ` Bart Schaefer
1998-06-12  9:26 ` Zefram
1998-06-12  9:55 ` Hannu Koivisto
1998-06-12 23:07 ` Thomas Köhler
1998-06-13 11:02   ` rename THIS=THAT Sven Guckes
     [not found]     ` <Pine.SOL.3.95.980613090415.15614A-100000@x139-110.med.umn.edu>
1998-06-15  0:37       ` zsh - rename THIS=THAT - mv $a $a:s/THIS/THAT/ Sven Guckes
     [not found] <Pine.SOL.3.95.980612084320.12190A-100000@x139-110.med.umn.edu>
1998-06-12 15:53 ` help with 'rename' function Timothy J Luoma
1998-06-12 16:21   ` Geoff Wing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199806120909.LAA21384@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=luomat+Lists/Zsh/users@luomat.peak.org \
    --cc=zsh-users@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).