How to do mv *.xyz *.abc in shell script??

Tim McDaniel mcdaniel at adi.com
Sat Sep 8 01:00:28 AEST 1990


This is from Dan LaLiberte of the University of Illinois at
Urbana-Champaign.  I've used it for years.  The conversion to
Bourne-shell syntax should be obvious.  Usage is like
	rename 's/\.xyz$/abc/' *.xyz

#! /bin/csh -f
#/* Written  7:36 pm  May 29, 1988 by liberte at uiucdcsm.cs.uiuc.edu in
# uicsrd.csrd.uiuc.edu:comp.sources.d */
# Here is my rename script.
#
# Dan LaLiberte
# liberte at a.cs.uiuc.edu
# uiucdcs!liberte
#
# ---
#
# rename files with a sed command.  File names may have spaces in them.

if ($#argv < 2) then
	echo "Usage: rename sed-command file ..."
	exit (1)
endif
set command = "$1"
shift
set noglob
while ($#argv > 0)
	set name = ($argv[1])
	shift
	set newname = `echo "$name" | sed -e "$command"`
	if ($status != 0) exit 1
	echo "mv -i $name $newname"
	mv -i "$name" "$newname"
end
exit 0

# /* End of text from uicsrd.csrd.uiuc.edu:comp.sources.d */
--
Tim McDaniel                 Applied Dynamics Int'l.; Ann Arbor, Michigan, USA
Work phone: +313 973 1300                            Home phone: +313 677 4386
Internet: mcdaniel at adi.com                UUCP: {uunet,sharkey}!amara!mcdaniel



More information about the Comp.unix.shell mailing list