Any one please help
My Requirement:
Actually i grep for the items in atrblist (i wil get the line where the that item present and also the next line)then it will be stored in $i.txt
From tat result i wil grep 2nd word after getdate() word and store it in $i_value.txt
eg: if result of $i.txt is below,
---------------------------------------------:
..'getdate(),NULL,'D','Y',NULL.....
..'Y',NULL, getdate(), NULL,'V','Y',NULL
..'getdate(),NULL,'A','Y',NULL.....
---------------------------------------------
Then result of $i_value.txt is,
---------------------------------------------
'D'
'V'
'A'
---------------------------------------------
Then i wil check whether $i is retention_cd and for values in $i_value.txt
if the value is 'A' or 'B' ... 'Z' i wil print the echo accordingly
if $i is opt_fmt_cd and for values in $i_txt
if values is PDF, XLS ... i wil print accordingly...
Above is my requirement
but the code does not work properly can any one please check my code and let me know the correct one....
NOTE:::: atrblist will be added with som new items also.
--------------------------- CODE STARTING ------------------------------------------------------------
for i in `cat $LOC/atrblist.txt`
do
echo "Registration Validation as of :" `date` > $LOC/$i.txt
nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=0 a=1 s=$i $SQLFILE >> $LOC/$i.txt
if [ $? -eq 1 ]
then
rm -f $LOC/$i.txt
exit 1
else
chmod 775 $LOC/$i.txt
cat $LOC/$i.txt | sed "s/getdate()/~&1/" | tr "~" "\n" | grep "getdate()" | cut -d"," -f3 >> $LOC/$i_value.txt
chmod 775 $LOC/$i_value.txt
if [ $i -eq retention_cd ]
then
for j in `cat \$i\_value.txt`
do
if [ $j -eq 'A' ]
then
echo "Values is" $j "So Retention code of product is : 7 Days"
else if [ $j -eq 'B' ]
then
echo "Values is" $j "So Retention code of product is : 3 Months"
else if [ $j -eq 'C' ]
then
echo "Values is" $j "So Retention code of product is : 1 Year"
else if [ $j -eq 'D' ]
then
echo "Values is" $j "So Retention code of product is : 10 Years"
else if [ $j -eq 'Z' ]
then
echo "Values is" $j "So Retention code of product is : 1 Day"
else
echo "Values is" $j "So Retention code is NOT VALID Please register correctly - Even it can be Empty but not NULL"
fi
fi
fi
fi
fi
done
fi
if [ $i -eq opt_fmt_cd ]
then
for j in `cat \$i\_value.txt`
do
if [ $j -eq 'PDF' ]
then
echo "Values is" $j "So Optional Format code of product is : PDF"
else if [ $j -eq 'XLS' ]
then
echo "Values is" $j" So Optional Format code of product is : XLS"
else if [ $j -eq 'CSV' ]
then
echo "Values is" $j" So Optional Format code of product is : CSV"
else if [ $j -eq 'TXT' ]
then
echo "Values is" $j" So Optional Format code of product is : TXT"
else
echo "Values is" $j "So Optional Format code which is NOT VALID Please register correctly"
fi
fi
fi
fi
done
fi
fi
done
--------------------------- CODE END ------------------------------------------------------------
where,
atrblist.txt is
----------------
retention_cd
opt_fmt_cd
;;
;;
-----------------
LOC = /home/path (local path)
SQLFILE:
---------------------------------------
;;
;;
values('new','retention_cd','retention_cd','C','EQUALS','N',-999, NULL,NULL,'N','N',NULL, NULL,'SYSTEM',getdate(),'0','D','0','S','N',0,'N','N','00',NULL1,NULL2,'N',NULL3,NULL4,NULL)
values('new1','opt_fmt_cd','retention_cd','C','EQUALS','N',-999, NULL,NULL,'N','N',NULL, NULL,'SYSTEM',getdate(),'0','D','0','S','N',0,'N','N','00',NULL1,NULL2,'N',NULL3,NULL4,NULL)
;;
;;
---------------------------------------