using awk loop

Hi, Gurus,
I have a requirement as following:
source data:

103,8,25

I want to get

103 8 25 1_8
103 8 25 9_16
103 8 25 17_24
103 8 25 25_32
103 8 25 33_40
103 8 25 41_48
103 8 25 49_56
103 8 25 57_64
103 8 25 65_72
103 8 25 73_80
103 8 25 81_88
103 8 25 89_96
103 8 25 97_104
103 8 25 105_112
103 8 25 113_120
103 8 25 121_128
103 8 25 129_136
103 8 25 137_144
103 8 25 145_152
103 8 25 153_160
103 8 25 161_168
103 8 25 169_176
103 8 25 177_184
103 8 25 185_192
103 8 25 193_200
103 8 25 201>

It is 26 records, last record is 201>

currently, I am using following command

awk  -F',' '{for(i=1; i<=$3+1; i++)print $1","$2","$3","((i-1)*$2+1)"_"$2*i}' 

i got most of it, only last record is

103, 8, 25, 201_208.

:wall:
can anyone help me out.

Thanks in advance.

awk -F',' '{for(i=1; i<$3+1; i++)print $1","$2","$3","((i-1)*$2+1)"_"$2*i; print $1","$2","$3","((i-1)*$2+1);}'

Hi, Chirel,
Thanks for you quick reply.
I got another issue. I need print one more column with command

awk -F',' '{for(i=1; i<$3+1; i++)print $1,$2,$3,$2*i,((i-1)*$2+1)"_"$2*i; print $1,$2,$3,((i-1)*$2+1)">";}' OFS=',' filename

I need get result

103,8,25,25,200,193_200
103,8,25,26,,201>

but current code give me following result.

103,8,25,25,200,193_200
103,8,25,26,201>

if I change the code to

awk -F',' '{for(i=1; i<$3+1; i++)print $1,$2,$3,$2*i,((i-1)*$2+1)"_"$2*i; print $1,$2,$3,,((i-1)*$2+1)">";}' OFS=',' filename

I got
103,8,25,25,200,193_200
103,8,25,26,,,201>

any idea to fix this issue?

Thanks again.

Here is one way of doing it:

#!/usr/bin/ksh
typeset -i mFrom=1
typeset -i mTo
while [[ ${mFrom} -le 201 ]]
do
  mTo=${mFrom}+7
  echo "$1 $2 $3 ${mFrom}_${mTo}"
  mFrom=${mTo}+1
done

do you mean ?

echo "103,8,25" | awk -F',' '{for(i=1; i<$3+1; i++)print $1,$2,$3,$2*i,((i-1)*$2+1)"_"$2*i; print $1,$2,$3,","((i-1)*$2+1)">";}' OFS=','

problem fixed with following code, Thanks everybody.

awk -F',' '{for(i=1; i<$3+1; i++)print $1","$2","$3","$2*i","((i-1)*$2+1)"_"$2*i; print $1","$2","$3","","((i-1)*$2+1);}' filename