From: Paul Lew <lew@ezdzit.zko.dec.com>
To: zsh-users@math.gatech.edu
Subject: Re: help with 'rename' function
Date: Sun, 14 Jun 1998 16:05:53 -0400 [thread overview]
Message-ID: <9806142005.AA00932@ezdzit.zko.dec.com> (raw)
In-Reply-To: <199806120909.LAA21384@hydra.ifh.de>
>>>>> "Peter" == Peter Stephenson <pws@ifh.de> writes:
Peter> 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.
Peter> It's perennially annoying UNIX doesn't have this. On the
Peter> other hand, if it did it would probably be so inscrutable
Peter> as to be almost useless.
I have been using the DOS style rename under Unix for years, i.e.,
(1)ezdzit lew x>> touch {a,b,c,d,e}.c
(1)ezdzit lew x>> ls
a.c b.c c.c d.c e.c
(1)ezdzit lew x>> ren *.c *.d
(1)ezdzit lew x>> ls
a.d b.d c.d d.d e.d
Yes, this can be done under Unix with some tweak. The following alias
and function definition actually called a csh script to do the real
work which can be converted to zsh. As you can see I have been using
this before the birth of zsh.
alias ren='set -F; rena'
function rena () {
set -F
renam $*
set +F
}
#! /bin/csh -f
#
#- rename - VMS style rename used for wildcard renaming
#-
#- This is to facilitate some desirable VMS feature on Unix. For
#- example:
#- $ mv *.c *.c00
#- $ mv abc.* def.*
#-
#- Another tool 'move' which use sed to change file name is more
#- general purpose than 'rename' or the 'rename.net' written by
#- Juergen Wagner <gandalf@csli.stanford.edu>.
#-
# Author: Paul Lew, General Systems Group, Inc.
# Created at: 03/02/88 01:48 PM
# Last update: 07/29/88 06:01 PM (Edition: 23)
#
#- Usage: rename old new
#- where: there must be one '*' in both old and new
#-
#---------------------------------------------------------------#
# Display help if requested by user #
#---------------------------------------------------------------#
switch ( "$1" )
case -H[xX]:
set echo; set verbose; shift
breaksw
case -H*:
show_help `which $0` $1
goto end
default:
endsw
#---------------------------------------------------------------#
# Process Arguments #
#---------------------------------------------------------------#
if ( $#argv != 2 ) then
show_help `which $0`
goto end
endif
#---------------------------------------------------------------#
# Process each item in the argument list #
#---------------------------------------------------------------#
set src = "$1"
set dest = "$2"
set cmd
set noglob
if ( ( "$1:r" != '*' && "$1:e" != '*' ) || \
( "$2:r" != '*' && "$2:e" != '*' ) ) then
echo "wildcard characters required on both src and dest"
goto end
endif
if ( "$src:r" == "$dest:r" && "$src:r" == '*' ) then
set same_root
else if ( "$src:e" == "$dest:e" && "$src:e" == '*' ) then
set same_ext
else if ( "$src:r" == "$dest:e" && "$src:r" == '*' ) then
set r_to_e
else if ( "$src:e" == "$dest:r" && "$src:e" == '*' ) then
set e_to_r
endif
unset noglob
set nonomatch
foreach file ($src)
if ( "$file" == "$src" ) then
echo "...File: $file not found, aborted..."
goto end
endif
if ( $?same_root ) $cmd mv $file ${file:r}.${dest:e}
if ( $?same_ext ) $cmd mv $file ${dest:r}.${file:e}
if ( $?r_to_e ) $cmd mv $file ${dest:r}.${file:r}
if ( $?e_to_r ) $cmd mv $file ${file:e}.${dest:e}
end
#---------------------------------------------------------------#
# Clean up and exit here... #
#---------------------------------------------------------------#
end:
unset src dest file
next prev parent reply other threads:[~1998-06-14 20:14 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
1998-06-14 20:05 ` Paul Lew [this message]
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=9806142005.AA00932@ezdzit.zko.dec.com \
--to=lew@ezdzit.zko.dec.com \
--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).