need help in reading a output of a sql query in unix script

i'm used a sql query in a unix script to get the information from table. but unable to extract the output which i need. Any help with logic will be greatly appreciated.

my sql query provide output some thing like this -

col1 col2 count
---- ---- ------
A B 10
c D 6
e f 3

i need some ideas to get the counts values from the output displayed.

2 possible ways
1) from your SQL query, sum up the columns. I believe there should be some sort of sum() function
2) you can try this

awk 'NR>1 && !/^-/{ s+=$3 }END{print "Sum: " s}' sqloutput

you can redirect the SQL o/p in a temp file something like $$ and take the 3rd column using awk....:b:

no need to :slight_smile:

i could extract the third column but i'm looking for logic some thing like using conditions to check col1 and col2 and check value at col3 is greater than 0.

why is it that you don't check these during your SQL query?

Ghostdog74 I'm new to unix scripting can you please explain what exactly this command does

awk 'NR>1 && !/^-/{ s+=$3 }END{print "Sum: " s}'

NR=record number
!/^-/ = lines that doesn't start with -
s+=$3 = <guess what it does>

your description is too vague to translate into code segment. You'd better describe in details how you gonna check the first two columns before others can post the solution;)