Connect to DB inside awk script

In a shell script, we can connect to the database using sqlplus on unix. can i accomplish the same thing inside awk script? I need to access the output of a select query inside awk script.is what is possible?

+2


source to share


2 answers


I would run the request and feed its output to awk:

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

      



Like any other command:

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

      

+3


source


Just use some command line client for your SQL database (if any) and output to awk

.

eg. with sqlite

(I don't know what the SQL * Plus client has):



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

      

awk

can't do it. This is the philosophy of UNIX tools, instead of having few tools that do many things, you use many small tools that do a single task and put them together.

+2


source







All Articles