selecting data in shell script
Posted in 2005
Topics: General Discussion
hello all,
it may very easy but I couln't find any solution.
I want to select data from table in command line or inside the shell script.
inserting data in shell script is possible with dbload command and did
it but I don't know how select is.
is there any way?
mustafa sert
Hi,
You may do it :
1 - cat ${DBADIR}/sql/INFtable.sql | dbaccess sysmaster >
${DBADIR}/log/new_INF_t
able1_${INFORMIX_DBID}.log
2- dbaccess sysmaster <<EOF
set isolation to dirty read;
set lock mode to wait;output to $TEMPFILE1
select tabname,(npused*2) size from sysptprof,sysptnhdr
where sysptprof.partnum = sysptnhdr.partnum and (npused*2)>25000000
and tabname not like ('°001235000')
order by 2 desc;EOF
Best Regards
Diane Lavoie
-----Original Message-----
From: forum.subscriber@iiug.org [mailto:forum.subscriber@iiug.org] On
Behalf Of mustafa sert
Sent: Monday, June 27, 2005 9:45 AM
To: ids@iiug.org
Subject: selecting data in shell script [5264]
hello all,
it may very easy but I couln't find any solution.
I want to select data from table in command line or inside the shell
script.
inserting data in shell script is possible with dbload command and did
it but I don't know how select is.
is there any way?
mustafa sert
You can use the dbaccess UNLOAD verb to export data to a delimited text file,
or
the OUTPUT verb to output to a formatted file. You can also use dbaccess in
commandline mode (dbaccess <databasename> - ) with a 'here script' to send
commands to and display results of queries. Another option is to use Jonathan
Leffler's sqlcmd package which has various output formatting options, is always
in commandline mode, and provides a server mode for handling multiple queries
without the overhead of making a new connection to the database and starting a
new copy of dbaccess or sqlcmd for each query.
Sqlcmd is available from the IIUG Software Repository.
Art S. Kagel
----- Original Message -----
From: Mustafa Sert <msert@meteor.gov.tr>
At: 6/27 11:27
hello all,
it may very easy but I couln't find any solution.
I want to select data from table in command line or inside the shell script.
inserting data in shell script is possible with dbload command and did
it but I don't know how select is.
is there any way?
mustafa sert
mustafa sert said:
> hello all,
> it may very easy but I couln't find any solution.
> I want to select data from table in command line or inside the shell
> script.
> inserting data in shell script is possible with dbload command and did
> it but I don't know how select is.
> is there any way?
dbaccess dbname <<!EOF
select * from tabname!EOF
--
Bye now,
Obnoxio
"C'est pas parce qu'on n'a rien à dire qu'il faut fermer sa gueule"
- Coluche
A smile is a gift that is free to the giver and precious to the recipient.
But giving someone the finger is free too, and I find it more personal and
sincere.
example,
with thanks to Art Kagel :
capture in variable :
tblist()
{
db=$1
std_err=/dev/null
dbaccess $db - 2>${std_err} <<%% | sed -e '/^$/d'
output to pipe "cat" without headings
select unique tabname from systables
where partnum != 0
and tabtype = "T"
order by 1;%%
do
TBLIST=`tblist $DB`
for TBL in $TBLIST
do
...
done
or
capture in unloaded file and then awk the file :
dbaccess $DB - <<eof >>err$$ 2>>err$$
unload to /tmp/unl1$$select d.dbsname ... etc
eof
cat /tmp/unl1$$ | awk ...
-----Original Message-----
From: nobody@ace.iiug.org [mailto:nobody@ace.iiug.org]
Sent: 27 June 2005 15:45
To: ids@iiug.org
Subject: selecting data in shell script [5264]
hello all,
it may very easy but I couln't find any solution.
I want to select data from table in command line or inside the shell script.
inserting data in shell script is possible with dbload command and did
it but I don't know how select is.
is there any way?
mustafa sert
------_=_NextPart_001_01C57BA4.273B0700
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=US-ASCII">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>RE: selecting data in shell script [5264] </TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2>example, with thanks to Art Kagel :</FONT>
</P>
<P><FONT SIZE=2>capture in variable :</FONT>
</P>
<P><FONT SIZE=2>tblist()</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR><FONT SIZE=2> db=$1</FONT>
<BR><FONT SIZE=2> std_err=/dev/null</FONT>
<BR><FONT SIZE=2> dbaccess $db - 2>${std_err} <<%% | sed -e
'/^$/d'</FONT>
<BR><FONT SIZE=2> output to pipe "cat" without headings</FONT>
<BR><FONT SIZE=2> select unique tabname from systables</FONT>
<BR><FONT SIZE=2> where partnum != 0</FONT>
<BR><FONT SIZE=2> and tabtype =
"T"</FONT>
<BR><FONT SIZE=2> order by 1;</FONT>
<BR><FONT SIZE=2>%%</FONT>
<BR><FONT SIZE=2>do</FONT>
<BR><FONT SIZE=2> TBLIST=`tblist $DB`</FONT>
<BR><FONT SIZE=2> for TBL in $TBLIST</FONT>
<BR><FONT SIZE=2> do</FONT>
<BR><FONT SIZE=2> ...</FONT>
<BR><FONT SIZE=2> done</FONT>
</P>
<P><FONT SIZE=2>or </FONT>
</P>
<P><FONT SIZE=2>capture in unloaded file and then awk the file :</FONT>
</P>
<P><FONT SIZE=2> dbaccess $DB -
<<eof >>err$$ 2>>err$$</FONT>
<BR><FONT SIZE=2> unload to
/tmp/unl1$$</FONT>
<BR><FONT SIZE=2> select
d.dbsname ... etc </FONT>
<BR><FONT SIZE=2> eof</FONT>
<BR><FONT SIZE=2> cat /tmp/unl1$$ | awk
...</FONT>
</P>
<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: nobody@ace.iiug.org [<A
HREF="mailto:nobody@ace.iiug.org">mailto:nobody@ace.iiug.org</A>] </FONT>
<BR><FONT SIZE=2>Sent: 27 June 2005 15:45</FONT>
<BR><FONT SIZE=2>To: ids@iiug.org</FONT>
<BR><FONT SIZE=2>Subject: selecting data in shell script [5264] </FONT>
</P>
<P><FONT SIZE=2>hello all,</FONT>
<BR><FONT SIZE=2>it may very easy but I couln't find any solution.</FONT>
<BR><FONT SIZE=2>I want to select data from table in command line or inside
the shell script.</FONT>
<BR><FONT SIZE=2>inserting data in shell script is possible with dbload
command and did </FONT>
<BR><FONT SIZE=2>it but I don't know how select is.</FONT>
<BR><FONT SIZE=2>is there any way?</FONT>
<BR><FONT SIZE=2>mustafa sert</FONT>
</P>
<BR>
</BODY>
</HTML>
------_=_NextPart_001_01C57BA4.273B0700--