Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
help with 'rename' function
- X-seq: zsh-users 1592
- From: Timothy J Luoma <luomat+Lists/Zsh/users@xxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxxxxxxx
- Subject: help with 'rename' function
- Date: Fri, 12 Jun 98 04:15:57 -0400
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
}
		
Messages sorted by:
Reverse Date,
Date,
Thread,
Author