Re: using the output of a sql statement in a shell script
Posted in 1998
In article <35D3E96D.79CDE7F4@ana.med.uni-muenchen.de>,
richard.spitz@ana.med.uni-muenchen.de wrote:
> josephatlanta@my-dejanews.com wrote:
> > 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?
>
> Yes, there is (almost). Use the "OUTPUT" command with the "WITHOUT HEADINGS"
> option. And redirect "stderr" to "/dev/null" since the "xx rows retrieved"
> goes to stderr.
>
> > 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.
>
> response=`
> {
> dbaccess ${dbname} - <<EOF
> output to pipe cat without headings
> select switch_id from switches where switch_id4 = "M1"> EOF
> } 2>/dev/null `
>
> HTH, Richard
> --
> +--------------------------+------------------------------------------+
> | Dr. Richard Spitz | INTERNET: spitz@ana.med.uni-muenchen.de |
> | EDV-Gruppe Anaesthesie | Tel : +49-89-7095-3413 |
> | Klinikum Grosshadern | FAX : +49-89-7095-8886 |
> | 81366 Munich, Germany | GSM : +49-172-8933578 |
> +--------------------------+------------------------------------------+
>
Richard's answer describes a good way to do it. let me add that you maybe will
get a blank line therefore I pipe it to a shell script containing the
folling trivial awk instead of pipe to cat:
get_rid_of_those_darn_blank_lines.sh
#!/bin/sh
#
awk ' $0 !~ /^$/ { print $0 } '
I don't know, if this is an appropriate solution - blank lines could have
a special meaning, if they appear in the data.
It works fine for me
Dick
--
Richard Kofler
EDVg-debis Systemhaus
Vienna / Austria
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum