Your code:
sqlq(){
result=`sqlplus -S sss/eee@sid < $1|grep -v '^$'`
echo $result
}
echo "select * from emp" > q.sql
sqlq q.sql
The echo and the variable in the sqlq function are not needed:
sqlq () {
sqlplus -S "sss/eee@sid" < "$1" | grep -v '^$'
}
This will send the output of the function to standard output (as it did before).
When calling the function, you may redirect its output to a file:
cat >query.sql <<END_SQL
SELECT * FROM emp;
END_SQL
sqlq query.sql >result.out
The reason I'm using a here-document here is that it makes it very easy to create multi-line SQL queries:
cat >query.sql <<END_SQL
SELECT data.*
FROM data
JOIN attributes ON (data.attr_id = attributes.attr_id)
WHERE attributes.name = "Example";
END_SQL
... for example.