Replace characters in all file names in a particular directory

Hi,

I have searched the forum on how to mass replace the file names. We are doing the migration and I am trying to accomplish a task where I have to replace all UNIX scripts in a particular directory that start with bdw to fdm...

For example: bdw0110137.sh should be fdm0110137.sh

Keep the existing script bdw0110137.sh and the contents in it and also have another script fdm0110137.sh with the same contents. Just like copying it into another script but with 'fdm' in the beginning.

I tried using the cut command, and also tried to change the code I found in the forum.

I would appreciate if you could help me in this regard.

Thank You,
Madhu

#!/bin/ksh
for e in *;
do mv "$e" "`echo $e | sed -e 's/\bdw/fdm/g'`";
done

But it changed the internal contents of the file too....

Is there a better way to achieve this?

for f in bdw* ;do
echo mv $f fdm${f%bdw}
done

#!/bin/csh
# Note - run in proper directory
#
ls -1 fdm* > /tmp/bdw.list
set filelist=`cat /tmp/bdw.list`
foreach x ($filelist)
        set newname=`echo $x|sed 's/fdm/bdw/g'`
        echo $newname
        cp $x $newname
end

oops! slight error should be # not %

#!/bin/bash

for f in bdw* ;do
        echo mv $f fdm${f#bdw}
done