parsing problem with script

I'm trying to parse the variables out of a comma delimited expression, but i'm having trouble with script:

num_var=1
while [ $num_var -lt 4 ]
do
a=`echo "a=7, b=8, c=9" | awk '{print $num_var}' | cut -d= -f2`
b=`echo $a | cut -d, -f1`
echo $b
num_var=`expr $num_var + 1`
done

the output is:

7
7
7

I know the problem is in the statement print $num_var ... for each time in the loop I want that print statement to be "print $1" then "print $2" then "print $3". How would I go about doing this using my num_var expression?

If i understand correctly, what u want is that three comma separated values should be printed in separate lines(in this case 7,8,9).

This should do it:

echo "7,8,9" | awk -F"," '{OFS="\n"; print $1,$2,$3}'

but i just can't have them listed "7, 8, 9" as there are variable names listed with the values...that is why I have to do the second cut. Is there any way to implement with a correction to the way I have it????

You can use:

  echo "a=7,b=8,c=9" | awk -F"[=,]" '{OFS="\n"; print $2,$4,$6}'  

or
If you have input like:

a=7
b=8
c=9

Then use :

  echo "$a,$b,$c" | awk -F"," '{OFS="\n"; print $1,$2,$3}'  

Also, you can't directly access shell variables in awk. To do what you are trying using your code :

num_var=1
while [ $num_var -lt 4 ]
do
a=`echo "a=7, b=8, c=9" | awk -v field=$num_var '{print $field}' | cut -d= -f2`
b=`echo $a | cut -d, -f1`
echo $b
num_var=`expr $num_var + 1`
done

This might help you

echo "a=7,b=8,c=9" | awk -F"," '{ for ( i = 1; i <= NF; i++) { print substr($i,3,1) ; } } '

thanks for the help you guys, it worked fine.