RE: using the output of a sql statement in a shell script
Posted in 1998
try
isql -d database - 2>/dev/null << !
select * from foo;!
stderr (where the number of rows returned is displayed) is piped to the bit
bucket. Your SQL code is read in from the succeeding lines until of course
it sees the "!". Don't screw around with the "!" too much, "^ !" is
different than "^!" and may not get recognized.
Of course you still have to worry about the headers. What I prefer to do
is
OUTPUT WITHOUT HEADERS TO filename (forgive me I'm sure I have the
syntax/spelling wrong here)
select statement;
Alas this has a problem in that if your output would exceed 80 columns it
gets reformatted to one (data) column per line - so you use reformat from
www.iiug.org to correct that, but much more simply:
UNLOAD TO file SELECT * FROM foo;
This gives you your data in a file like you wanted with lovely "|"
delimiters - which of course you can change by modifying $DBDELIMITER.
Make sure you use this code with a salt-shaker. It's been a while since
I've been allowed to touch a keyboard and while the ideas are there I think
I'd check the syntax.
cheers
j.
"Ashby, David" <David.Ashby@workcover.nsw.gov.au> on 08/14/98 01:57:33 AM
To: "'joseph.luczynski@mindspring.com'"
<joseph.luczynski@mindspring.com>, informix-list@iiug.org
cc: (bcc: Jack Parker/Boston50/Epsilon)
Subject: RE: using the output of a sql statement in a shell script
Joseph,
No there isn't. Just use something like "tail +3 file | sed '/row(s)
retrieved/d' to eliminate the rows.
Regards
David Ashby
-----Original Message-----
From: joseph.luczynski@mindspring.com
[mailto:joseph.luczynski@mindspring.com]
Sent: Friday, 14 August 1998 3:45
To: informix-list@iiug.org
Subject: using the output of a sql statement in a
shell script
Is there a SQL statement that can give me the output of
the switches without
the "switch_id" and/or the "14 row(s) retreived." text?
There may be any amount of switches, and I either need
to write the shell
script to parse the extra text out, or get the SQL
statement to omit it.
Thanks for your help!
================================================
response=`
{
dbaccess ${dbname} - <<EOF
select switch_id from switches where switch_id4 = "M1"
EOF
} 2>&1 `
echo $response
#switch_id RIM 2JY 2JV CLX 2OR ASC AU1 AUP BCS AUA AUO
BOY BHW 2M8 14 row(s)
retrieved.
-----== Posted via Deja News, The Leader in Internet
Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own
Free Member Forum