reddyr
September 8, 2014, 11:31am
1
Hi,
I have hundreds of files with XXX
in their file name and I want to rename all of them with YYY
in place of XXX
.
for ex:
$ ls -1
123XXX789
345XXX678
Output
$ ls -1
123YYY789
345YYY678
I know we can loop in each file and sed
to replace and rename each file but ren *XXX* *YYY*
worked in windows
but mv *XXX* *YYY*
did not in UNIX
Pls advise, TIA
vbe
September 8, 2014, 11:41am
2
Dont know about windows, but in UNIX world mv *XXX* *YYY*
meaning move all files with XXX inside their file to anything with YYY in their filename... how is the OS going to choose to what?
You have no other coice than using a loop...
Hello reddyr,
Following may help in same.
for file in *XXX*
do new_name=`echo $file | awk '{gsub("XXX","YYY",$0);print $0}'`
mv $file $new_name
done
Thanks,
R. Singh
RudiC
September 8, 2014, 1:08pm
4
for file in *XXX*
do mv $file ${file/XXX/YYY}
done
This will replace the first occurrence of XXX only using parameter expansion of recent shells.
drl
September 8, 2014, 2:51pm
5
Hi.
See also post # 4 in thread Rename more than 1 file and the warning in post # 8 in thread [SOLVED] Copy+Rename multiple files at once
Best wishes ... cheers, drl