file reading through shell script

For reading a file through shell script I am using yhe code :

while read line
do
echo $line
done<data.txt

It reads all the line of that file data.txt.
Content of data.txt looks like:

code=y
sql=y
total no of sql files=4
a.sql
b.sql
c.sql
d.sql
cpp=n
c=y
total no of c files=1
a.c
.....
.......

Now, if sql=y and total no of sql files > 0 then want to fetch the only sql file names via shell script.
the script should fetch
a.sql
b.sql
c.sql
d.sql

> cat temp.txt
code=y
sql=y
total no of sql files=4
a.sql
b.sql
c.sql
d.sql
cpp=n
c=y
total no of c files=1
a.c

> cat get_sql.ksh
echo "Enter the string.. \c";
read str
option=`grep "$str=" temp.txt|awk -F"=" '{print $2}'`
if [ "$option" = "y" ]
then
        nooffile=`grep "$str files=" temp.txt|awk -F"=" '{print $2}'`
        if [ "$nooffile" > "0" ]
        then
                echo "FILES...."
                grep "\.${str}" temp.txt
        fi
fi

[OUTPUT]
Enter the string.. sql
FILES....
a.sql
b.sql
c.sql
d.sql

Enter the string.. c
FILES....
a.c
[/OUTPUT]

Thanks a lot palsevlohit....its working fine.

It is also possible to do it all within a shell script without using external utilities such as grep i.e.

#!/usr/bin/bash

yes=0

IFS='='
while read line value
do
    [[ $line == "sql"  && $value == "y" ]] && ((yes++))
    [[ $line == "total no of sql files" && $value > "0" ]] && ((yes++))
    [[ $yes == 2 && ${line: -4} == ".sql" ]] && echo $line
done < file

call below script with whatever parameter you like, such as 'sql' or 'c' will print the result accordingly

nawk -v f="$1" -F"=" '{
if ($1==f && $2="y")
	f1=1
if(f1==1 && $2>0)
	f2=1
file=sprintf(".%s",f)
if(f2==1 && index($0,file)!=0)
	print $0
}' filename