Run DB2 export command in loop

Hi All,

I have list of 100 table names in a file, how to read table name from and pass to DB2 export command and run for all tables in loop.

Please help me with script.

db2 EXPORT TO ~/data_export/<table name from file>.ixf OF IXF MESSAGES messages.txt "SELECT * FROM ITG.<Table Name from file>"

Thanks
Srimitta

$ cat file_with_table_names
table1
table2
table3

$ xargs -I{} echo db2 EXPORT TO \~/data_export/{}.ixf OF IXF MESSAGES messages.txt \"SELECT \* FROM ITG.{}\" < file_with_table_names | sh

Hi Scott,

Thanks for the reply.

I ran script and getting below error message, any idea.

$ ksh -x export_db2_tables.ksh
+ cd /home/db2inst2/data_export/scripts/
+ cat table_names
table1
table2
table3
+ db2 connect to ITG

   Database Connection Information

 Database server        = DB2/AIX64 9.5.2
 SQL authorization ID   = DB2INST1
 Local database alias   = ITG

+ xargs -I{} db2 EXPORT TO ~/data_export/{}.ixf OF IXF MESSAGES messages.txt "SELECT * FROM ITG.{}"
+ 0< table_names
+ sh
sh: SQL0104N:  not found.
sh[2]: found:  not found.
sh[4]: SQL0104N:  not found.
sh[5]: found:  not found.
sh[7]: SQL0104N:  not found.
sh[8]: was:  not found.

Thanks
Srimitta

Hi.

Sorry about that :slight_smile:

while read TABLE; do
  db2 EXPORT TO ~/data_export/$TABLE.ixf OF IXF MESSAGES messages.txt "SELECT * FROM ITG.$TABLE"
done < file_with_table_names 

My globbing brain is not engaged! If it doesn't work, try changing * to \*

Thanks Scott, Excellent it's working.

Srimitta