zsh-users
 help / color / mirror / code / Atom feed
* help with 'rename' function
@ 1998-06-12  8:15 Timothy J Luoma
  1998-06-12  9:09 ` Peter Stephenson
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Timothy J Luoma @ 1998-06-12  8:15 UTC (permalink / raw)
  To: zsh-users


I used to have a binary that did this, but I've lost it.

What it did was simple: it changed extensions of filenames.

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
	
and it would go on its way... or if it was just one file:

	rename foo.THIS THIS=THAT
	
I've tried to make a function which does this, but it fails:

(the $others variable is ALL the file names rather than cycling through one by one)


rename () {

	local i last oldext newext short new others

	last=`echo $* | awk '{print $NF}'`
	
	# all the args except the last one
	others=`echo $* | sed "s/ $last$//g"`
	
	oldext=`echo $rename | tr -s '=' ' ' | awk '{print $1}'`
	newext=`echo $rename | tr -s '=' ' ' | awk '{print $2}'`
	
	echo "oldext is $oldext"
	echo "newext is $newext"
	


	for i in $others
	do
		short=`echo $i .$oldext`
		  new=`echo $short.$newext`
		
		mv   $i   $new
		
	done

}
		


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~1998-06-14 20:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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
1998-06-12  8:15 Timothy J Luoma
1998-06-12  9:09 ` Peter Stephenson
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

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).