Your best bet is something like
#!/bin/bash
get_data ()
{
QRY=$(psql $HOST $PORT $USER $DBNAME <<_QUERY_
\o your_output_file
SELECT col1, col2, ...., coln
FROM your_table
WHERE <blah>;
_QUERY_
)
}
awk <blah> your_table
I presume you mean "awk <blah> your_output_file" ...
David J.