output to a delimited file
Posted in 1999
Topics: SQL Development & Query Writing, Platform-Specific Issues
I have written a shell script that outputs to a flat file. I want to actually have a delimited flat file. If I use a command called selectfile I get a nice pipe delimited file but this does not let me pass to it a variable for the file name. There will be close to 200 similar reports generated from this program that I will import into excel. here is the code I used the select statement is accurate but the output to file does not give me the format I am looking for. If anyone could help me I would appreciate it. I am using Informix 5.2 on AIX 4.25 #1/bin/ksh for sponsor_id in `selectit 'select id from department'`;do filename=/home/kdt/sponsors/`eval selectit \\'select description[1,8] from department where id =$sponsor_id\\'`.out print -n "$sponsor_id " print $filename eval selectit \\'select table1.address1, table2.description, table1.last_name, table1.first_name, table1.initials, table1.address3, table1.address5, table1.address4, pin, table1.expired_date, table1sts.cond_desc, department.manager from table1, table1_type, table1sts, department, table2 where table1.dept = $sponsor_id and table1.type = table1_type.id and table1.status = table1sts.id and \\(colunm1 = table2.id or colunm2 = table2.id or colunm3 = table2.id or colunm4 = table2.id or colunm5 = table2.id or colunm6 = table2.id or colunm7 = table2.id or colunm8 = table2.id or colunm9 = table2.id or colunm10 = table2.id or colunm11 = table2.id or colunm12 = table2.id or colunm13 = table2.id or colunm14 = table2.id or colunm15 = table2.id or colunm16 = table2.id or colunm17 = table2.id or colunm18 = table2.id or colunm19 = table2.id or colunm20 = table2.id or colunm21 = table2.id or colunm22 = table2.id or colunm23 = table2.id or colunm24 = table2.id or colunm25 = table2.id or colunm26 = table2.id or colunm27 = table2.id or colunm28 = table2.id or colunm29 = table2.id or colunm30 = table2.id or colunm31 = table2.id or colunm32 = table2.id\\) and table1.dept = department.id order by 7,3,8\\' >$filename done thanks in advance kirtt@mediaone.net
You can use the DBACCESS UNLOAD command to get the delimited output
you seek:
UNLOAD TO "somefilename"SELECT description[1,8]
FROM department
WHERE id = <sponsor_id>;
Using a 'here script' you can even use the $sponsor_id environment
variable to supply the value for the where clause.
Art S. Kagel
kirt wrote:
>
> I have written a shell script that outputs to a flat file. I want to
> actually have a delimited flat file. If I use a command called selectfile I
> get a nice pipe delimited file but this does not let me pass to it a
> variable for the file name. There will be close to 200 similar reports
> generated from this program that I will import into excel. here is the code
> I used the select statement is accurate but the output to file does not give
> me the format I am looking for. If anyone could help me I would appreciate
> it. I am using Informix 5.2 on AIX 4.25
>
> #1/bin/ksh
>
> for sponsor_id in `selectit 'select id from department'`;do
> filename=/home/kdt/sponsors/`eval selectit \\'select description[1,8] from
> department where id =$sponsor_id\\'`.out
> print -n "$sponsor_id "
> print $filename
> eval selectit \\'select table1.address1, table2.description,
> table1.last_name, table1.first_name, table1.initials, table1.address3,
> table1.address5, table1.address4, pin, table1.expired_date,
> table1sts.cond_desc, department.manager from table1, table1_type, table1sts,
> department, table2 where table1.dept = $sponsor_id and table1.type =
> table1_type.id and table1.status = table1sts.id and \\(colunm1 = table2.id or
> colunm2 = table2.id or colunm3 = table2.id or colunm4 = table2.id or colunm5
> = table2.id or colunm6 = table2.id or colunm7 = table2.id or colunm8 =
> table2.id or colunm9 = table2.id or colunm10 = table2.id or colunm11 =
> table2.id or colunm12 = table2.id or colunm13 = table2.id or colunm14 =
> table2.id or colunm15 = table2.id or colunm16 = table2.id or colunm17 =
> table2.id or colunm18 = table2.id or colunm19 = table2.id or colunm20 =
> table2.id or colunm21 = table2.id or colunm22 = table2.id or colunm23 =
> table2.id or colunm24 = table2.id or colunm25 = table2.id or colunm26 =
> table2.id or colunm27 = table2.id or colunm28 = table2.id or colunm29 =
> table2.id or colunm30 = table2.id or colunm31 = table2.id or colunm32 =
> table2.id\\) and table1.dept = department.id order by 7,3,8\\' >$filename
> done
>
> thanks in advance
> kirtt@mediaone.net