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