I am unable to read single VALUE from mysql Query in awk.I am able to read it in bash but not in awk. I want to read the result variable in awk as I want to fire the query only based on some dynamic conditions written in awk.
awk '{
cmd="(mysql --host='abc' --user='def' --password='..' --database='ghf' -sNe \"select VALUE from table where KEY='171-125';\")"
cmd|getline $lastdiff;
print "diff is "lastdiff;
}'
diff is
diff is
I have tried with grep -Eo \" [0-9]* \"
also/ It is not helping. I have used both system()
or cmd | getline
to get the result into variable but it is always returning 0.
sudo awk 'BEGIN {
> myvalue=system("mysql --host='abc' --user='def' --password='..' --database='ghf' -sNe \"select VALUE from table where KEY='171-125';\" ");
> print "diff is ",myvalue;
> }'
diff is 0
Bash is giving the result
mysql --host='abc' --user='def' --password='..' --database='ghf' -sNe "select VALUE from table where KEY='171-125';"
1
I want to read the numeric VALUE into lastdiff variable in awk. Any recommended solutions.