simple question about mv
James Logan III
logan at vsedev.VSE.COM
Mon Jan 30 06:59:15 AEST 1989
In article <18217 at adm.BRL.MIL> DEG41560 at ua1vm.ua.edu (Rob Smith) writes:
# I know this is simple, but then again, so am I. What if I want to mv a bunch
# of files with the same suffix to another suffix. The following does not
# work
#
# mv *.flip *.flop
#
# what does? I'm under Ultrix 2.2. I'm doing it by hand, but I'd like to
# be able to do wild card renames, ala DOS.
You will have to do this with a "for" loop. If you are using the
Bourne or the Korn shell, you can use the following loop. If you're
using the C shell, you're on your own.
for FILE in *.flip; do
NOEXTEN=`basename $FILE .flip`;
echo $FILE ${NOEXTEN}.flop;
mv $FILE ${NOEXTEN}.flop;
done;
I like having the echo in the above example so that if I make a
typo I can see the problem, before it's too late, and hit the
interrupt key.
That loop can be generalized into a shell script like this one:
-------------------------------------------------------
:
# mvex.sh James Logan Sun Jan 29 15:44:09 EST 1989
# Move all files with one extension to a new extension.
#
#
# Check the parameters.
#
if test $# -ne 2; then
echo >&2 "usage: $0 oldextension newextension";
exit 2;
fi;
#
# These variables can be optimized out, but are used for clarity.
#
OLDEXTENSION=$1;
NEWEXTENSION=$2;
#
# Move each file one at a time.
#
for FILE in *$OLDEXTENSION; do
NOEXTEN=`basename $FILE $OLDEXTENSION`;
mv $FILE ${NOEXTEN}${NEWEXTENSION};
done;
exit 0;
-------------------------------------------------------
-Jim
--
Jim Logan logan at vsedev.vse.com
VSE Software Development Lab uucp: ..!uunet!vsedev!logan
(703) 418-0002 inet: logan%vsedev.vse.com at uunet.uu.net
More information about the Comp.unix.wizards
mailing list