Putazo
August 16, 2009, 1:31am
1
Hello !
i have a few files like ...
setup.001
setup.002
setup.003
setup.004
// to
setup.095
and i would like to rename those files to ...
setup.r01
setup.r02
setup.r03
setup.r04
// to
setup.r95
how can i do that ???
thanks in advance !!
hope this will guide you..
echo "setup.001"|sed 's/.0/.r/g'
Putazo
August 16, 2009, 1:57am
3
wow thanks a lot !! it worked almost flawlessly !
i did ...
for file in setup.* ; do mv $file `echo $file | sed 's/.0/.r/g'` ; done
everything went right except i lost every "ten"
i got
setup.r01
//to
setup.r09
//but somehow i lost setup.r10
setup.r11
//to
setup.19
//but somehow i lost setup.r20
etc ...
i would need some regex to apply to tens
if i make
echo "setup.010"|sed 's/.0/.r/g'
i got ..
setup.r.r
unfortunately i don't know much about regex
Simple, use the rename command as
rename s/\.[0-9]/.r/ *
Putazo
August 16, 2009, 2:41am
5
i don't have the rename command in my shell
kshji
August 16, 2009, 4:44am
7
#!/bin/ksh
# or bash
# split filename using dot to the two variable
ls setup.* | while IFS="." read start end
do
oldname="$start.$end"
# substring starting from second char and give length nothing = rest of data
end="r${end:1}"
newname="$start.$end"
[ "$newname" = "$oldname" ] && continue
# remove echo if looks good
echo mv "$oldname" "$newname"
done
Putazo
August 16, 2009, 3:34pm
8
hey thanks all for your useful help ! i did the job perfectly
you may close the thread if you want