I need to alter this script to work with a revision instead of a version.
RF_102_209_200_v001_r01.nk is the new format and I'll be revisioning up the r01 portion and not the v001.
#!/bin/sh
for file in "$@"
do
ext=${file##*.}
base=${file%.*}
num=${base##*v}
zeroes=${num%%[!0]*}
num=${num#$zeroes}
num=$((num+1))
base=${base%v*}
new=$(printf '%sv%04d.%s' "$base" "$num" "$ext")
cp -nv "$file" "$new"
done
Yes well, unfortunately, I don't get to keep up with this stuff as often as I'd like, since this isn't really part of my job. I took a stab at it but failed miserably. So rather than have my boss come over and ask what the f' I'm doing writing code instead of actually working, I asked here.
Very good indeed. If you can run the script with bash , try also
IFS="_."
for file in *.nk
do read A B C D V R X <<< $file
printf "%s_%s_%s_%s_%s_r%02d.%s\n" $A $B $C $D $V $((10#${R#r} + 1)) $X
done
RF_102_209_200_v001_r02.nk
or
IFS="_."
for file in *.nk
do ARR=( $file )
printf "%s_%s_%s_%s_%s_r%02d.%s\n" ${ARR[0]} ${ARR[1]} ${ARR[2]} ${ARR[3]} ${ARR[4]} $((10#${ARR[5]#r} + 1)) ${ARR[6]}
done
RF_102_209_200_v001_r02.nk
Don't forget to reset IFS to its original value.
If all your file names are set to the positional parameters, try
IFS=$'\n'
while IFS="_." read A B C D V R X
do printf "cp %s_%s_%s_%s_%s_%s.%s %s_%s_%s_%s_%s_r%02d.%s\n" $A $B $C $D $V $R $X $A $B $C $D $V $((10#${R#r} + 1)) $X
done <<< "$*"
cp RF_102_209_200_v001_r01.nk RF_102_209_200_v001_r02.nk
cp RF_102_209_200_v001_r04.nk RF_102_209_200_v001_r05.nk