I'm on AIX version 5 and I believe I have the tcsh shell environment to play in. Can you guys help me with a solution to rename all files that have "eclp" in the filename to "ecl" ? I basically want to rename the files and strip the "p" out.
Why you ask to use tcsh, if you have nothing ? Even your interactive command shell is tcsh, you can do your script using any shell which you have. And execute it even you use tcsh.
Example, I'm sure that you have sh in /bin directory, so this works, even it is ksh88 version or BourneShell - save this text to file rename.sh :
#!/bin/sh
#rename.sh
for f in $*
do
newname=`echo "$f" | sed "s/^grp_eclp_/grp_ecl_/" `
if [ "$newname" = "$f" ] ; then
echo "no rename $f"
continue
fi
echo "rename $f -> $newname"
mv "$f" "$newname"
done
And after you have created file rename.sh , give execute priviledges and then call rename.sh with those files which you like to rename.
chmod a+rx rename.sh
./rename.sh grp*ADTA*.xlt
# or
./rename.sh grp*.xlt
# or ...
Both are almost perfect :).
My version use dynamic filenames, your teams dynamic replace rule.
Your team version not chech, is there name change or not. My version check it.
So this is the best:
#!/bin/sh
#rename.sh
# arg1=old string
# arg2=new string
# arg3-n = files to make name editing
old="$1"
new="$2"
# remove 2 args, rest are filenames
shift 2
for f in $*
do
newname=`echo "$f" | sed "s/$old/$new/" `
if [ "$newname" = "$f" ] ; then
echo "no rename $f"
continue
fi
echo "rename $f -> $newname"
mv "$f" "$newname"
done