tags:

views:

203

answers:

2

Hi In a shell script we can connect to a Database using sqlplus on unix. can i perform the same thing inside an awk script? i need to access the output of a select query inside an awk script.is that possible?

+2  A: 

Just use some sort of command line client for your SQL database (if available) and pipe the output to awk.

E.g. with sqlite (I don't know what client SQL*Plus has):

echo "select * from foo;" | sqlite3 file.db | awk ...

awk can't do it. This is UNIX tools philosophy, instead of having few tools that do many tasks, you use many little tools that do one task and connect them together.

Alex B
+2  A: 

I'd do the query and feed the output of it into awk:

sqlplus 'select onething from another' | awk '{ weave awk magic here }'

Just like any other command:

pax> ls -alF | awk '{print $9}'
    file1.txt
    file2.txt
    my_p0rn_dir/
paxdiablo