You can do it all in shell without invoking external programs:
for f in *; do
mv -- "$f" "$f"_Normal
done
In addition, the shell-only solution won't break on pathological filenames.
You may also add nullglob (or test with -f) to avoid errors when there are no matching filenames.
Directory is having following files:
A_Normal
B_Normal
C_Normal
Etc tc
I would like to rename all the files without �_Normal�. After rename the file name should be:
A
B
C
Etc etc
I have written following code:
#!/bin/sh
for i in `ls`
do
echo Changing $i .............................
filename = 'basename $i _Normal'
mv "$i" "$filename"
done
But it is giving error like:
Changing A_Normal .............................
ksh: filename: not found.
mv: 0653-401 Cannot rename A_Normal to :
A file or directory in the path name does not exist.
Please help me in rectifying this error.
---------- Post updated 11-07-12 at 03:22 AM ---------- Previous update was 11-06-12 at 06:25 AM ----------
I corrected it by myself, posting it if it may help anyone else:
13:48:50 $ cat rename_files
#!/bin/sh
for i in `ls`
do
echo Changing $i .............................
filename=`basename $i _Normal`
#echo $filename
mv "$i" "$filename"
done
13:48:59 $