RE: SQL from korn shell
Posted in 1998
Being a novice with korn shell script programming, I pipe the results
of SQL command to "tail" and "head" commands to eliminate extra
blank lines. For example:
integer SYSUTILS_ROWNUM=`dbaccess sysutils 2>/dev/null <<- EOF!
OUTPUT TO PIPE 'tail +3 | head -1' WITHOUT HEADINGS
SELECT count(*)
FROM bar_instance
WHERE ins_aid < $1; EOF!`
It successfully returns a numeric value to the shell script variable.
However, someone else may have a better technique.
-----Original Message-----
From: mr_mark@my-dejanews.com [mailto:mr_mark@my-dejanews.com]
Sent: Thursday, October 29, 1998 13:40
To: informix-list@iiug.org
Subject: SQL from korn shell
I am trying to get a value from a database. I couldn't get the SELECT call
to just return a data value without the preceding newlines so I have the
OUTPUT TO command sending the output to a file which I then read to
eliminate
the newlines. All this is initiated from an awk script which has stdout
redirected to a file. The SELECT is in a korn shell script. The problem
is:
even if the SQL table query returns no value I get a newline printed to
stdout(my file) and it's not being done by me. Somehow, a dbaccess SQL call
automatically behind the scene puts a newline to stdout. Is there a way to
supress this newline and better yet to get the original value from the SQL
call into a variable. My code is below: # Arguments coming include
database,
field name being retreived, table to query # field to match key to and the
key gotten from the log file. These arguments # must come in this order.
dbaccess $1 - - << EOF 2>/dev/null
OUTPUT TO sqlout WITHOUT HEADINGS
SELECT $2
FROM $3
WHERE $4 = $5;
EOF
while read -r line
do
if [[ -z $line ]]
then
line=""
continue
fi
print -n "$line" > testfile
break
done < sqlout
rm -f sqlout
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own