My awk script searches for specified patterns in a text file and stores these values into mem variables.
Once this is done I want to Insert these values into a table.
How can I avail of the variable values outside the scope of awk script....
One method that I have tried is to write the variables values into a temp file with delimiters and then read these values from a shell script, form a connection to database and insert the values into table....But I feel this is doing things in a roundabout way....
What wud be a straighter approach ? I dont want to sacrifice the awk script !
The awk script now :
/Total logical records skipped:/ {skiprecs=$5;}
/Total logical records read:/ {readrecs=$5;}
/Total logical records rejected:/ {rejectrecs=$5;}
/Total logical records discarded:/ {discardrecs=$5}
END { totalfailrecs = skiprecs + rejectrecs + discardrecs ;
totalsuccessrecs = readrecs ;
totalrecs = totalfailrecs + totalsuccessrecs ;
printf "Printing the results "
printf ("\n")
printf ("Failed Records : %d\n", totalfailrecs);
printf ("Success Records : %d\n", totalsuccessrecs);
printf ("Total Records : %d\n", totalrecs);
printf ("%d,%d,%d",totalfailrecs,totalsuccessrecs,totalrecs)>>"tempfile"
}
I don't think we can retrieve values from awk to unix shell... when awk finishes we loose all it values... I can provide you another alternative method instead of creating and parsing it..
a1.awk
/Total logical records skipped:/ {skiprecs=$5;}
/Total logical records read:/ {readrecs=$5;}
/Total logical records rejected:/ {rejectrecs=$5;}
/Total logical records discarded:/ {discardrecs=$5}
END { totalfailrecs = skiprecs + rejectrecs + discardrecs ;
totalsuccessrecs = readrecs ;
totalrecs = totalfailrecs + totalsuccessrecs ;
printf ("%d,%d",totalfailrecs,totalsuccessrecs);
}
#/usr/bin/ksh
oput=$(awk -f a1.awk inputfile)
totalfailrecs=cut -d"," -f1
totalsuccessrecs=cut -d"," -f2
total_recs=$(($totalfailrecs+$totalsuccessrecs))
do what ever you want after this