Korn Shell Loop question

I'm needing help with assigning variables inside a while loop of ksh script.
I have an input text file and ksh script below and I'm trying to create a script which will read the input file line by line, assign first and second word to variables and process the variables according to the contents.

$ more file.txt
AAA 001
BBB 002
CCC 003
DDD 004

$ more looptest.ksh
#! /bin/ksh

while read line
do
   awk '{print FS,$1}' >> var1
   awk '{print FS,$2}' >> var2
   
   if [[ $var1 = AAA ]]
   then
           echo group1 $var2
   elif [[ $var1 =  CCC ]]
   then
           echo group2 $var2
    fi 
done < file.txt

The desired output for my ksh script is the below but the section where I assign first and second word to variables isn't working. Could someone tell me how to fix this?

group1 001
group2 003

awk '{print FS,$1}' >> var1
awk '{print FS,$2}' >> var2

You are redirecting the output to a file and not to a variable. And nowhere you are using the variable "line" in the awk statement. Change the above 2 lines as below and try again.

var1=`echo $line | awk '{print FS,$1}'`
var2=`echo $line |awk '{print FS,$2}'`

you can also use cut instead of awk to read the first and second word.

#! /bin/ksh
while read line
do
var1=`echo $line | cut -f1 -d" "` 
var2=`echo $line | cut -f2 -d" "`
   if [[ $var1 = AAA ]]
   then
           echo group1 $var2
   elif [[ $var1 =  CCC ]]
   then
           echo group2 $var2
    fi 
done < file.txt

you can also read the words in the while loop itself

#! /bin/ksh
while read var1 var2
do
   if [[ $var1 = AAA ]]
   then
           echo group1 $var2
   elif [[ $var1 =  CCC ]]
   then
           echo group2 $var2
    fi 
done < file.txt

Thank you very much mona!!
That's exactly what I wanted!!
BTW do you know any good sites for learning shell programming?

This page has several links to good sites.
http://stommel.tamu.edu/~baum/programming.html

Additionally, you could check this link for Korn shells specifically.
http://www.unix.org.ua/orelly/unix/ksh/