Versioning up a file with initials?

I have this code that works great ...

#!/bin/sh

for file in "$@"
do
        ext=${file##*.}
        base=${file%.*}
        num=${base##*v}
        zeroes=${num%%[!0]*}
        num=${num#$zeroes}      #remove leading zeros, or it uses octal
        num=$((num+1))
        base=${base%v*}
        new=$(printf '%sv%04d.%s' "$base" "$num" "$ext")
        cp -nv "$file" "$new"
done

Now I need it to work with a file that has two characters after the version number.
098_FGT_550_comp_v002gp.nk

I've tried just about everything I know to get this to work but it seems the characters get picked up as part of the number.

Any help is appreciated.

Thank you.

You could try adding these intermediate steps after num=${base##*v} to remove trailing characters after the last digit (what you call "initials"):

initials=${num##*[0-9]}
num=${num%"${initials}"}

That works but I lose the "initials."
The file produced is 098_FGT_550_comp_v0003.nk

Once I get this working, several different people will be using it, so I need it to restore the initials.

Not sure where the problem is:

printf '%sv%04d%s.%s' "$base" "$num" "$initials" "$ext"
 098_FGT_550_comp_v0002gp.nk

Your three digit version number has become four digit with your printf format.

Or, why not (provided you have a recent bash or ksh )

IFS="v."
ARR=( $file )
echo cp "$file" "$(printf '%sv%04d%s.%s\n' "${ARR[0]}" "$((10#${ARR[1]%%[^0-9]*} + 1))" "${ARR[1]##*[0-9]}" ${ARR[-1]})"
cp 098_FGT_550_comp_v002gp.nk 098_FGT_550_comp_v0003gp.nk

With the intermediate steps I suggested, the "initials" are saved in the initials variable, so you can use them wherever you please.
So try:

new=$(printf '%sv%04d%s.%s' "$base" "$num" "$initials" "$ext")

If they need to go somewhere else, then please specify the end result.

That works great!
Thank you.

It seems to easy now that I see it done correctly.