Problem running db2 commands in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem running db2 commands in awk
# 1  
Old 12-24-2015
Problem running db2 commands in awk

Hi ,

I am trying to use the below in awk but failed, any one assist please,
Code:
 awk '{ print $0; 
 if ( $0 ~ /LOADTMP1/ ) 
 { 
 print $4;
 Table_name=system($( db2 -x "SELECT TRIM(TD.BSCHEMA) || '.' || TRIM(TD.BNAME) AS TABLE_NAME FROM SYSCAT.TABDEP TD WHERE 
TD.BTYPE='T' AND TD.TABSCHEMA='XXXXXXX' AND  TD.TABNAME='$view' order by BSCHEMA desc fetch first 1 row only ));
 print $Table_name;
 }
 }' test

1. I have tried replacing ' with '\'' but no help
please assist.


Moderator's Comments:
Mod Comment Please use code tags! Thanks

Last edited by vbe; 12-24-2015 at 07:38 AM.. Reason: code tags
# 2  
Old 12-24-2015
Please use code tags as required by forum rules!

This is a hell of a quoting problem. Try
Code:
awk -v SQ="'" '
1
/LOADTMP1/      {print $4;
                 Table_name=system("db2 -x \"SELECT TRIM(TD.BSCHEMA) || " SQ "." SQ " || TRIM(TD.BNAME) AS TABLE_NAME FROM SYSCAT.TABDEP TD WHERE TD.BTYPE=" SQ "T" SQ " AND TD.TABSCHEMA=" SQ "XXXXXXX" SQ " AND TD.TABNAME=" SQ "$view" SQ " order by BSCHEMA desc fetch first 1 row only\"")
                 print Table_name;
                }
'  test

You may want to echo that sql string to verify it's correctly spelled...
# 3  
Old 01-04-2016
Hi, Thanks for your reply.

But this code returns "1" instead of table name.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Troubles running DB2 command in shell script via cron

Hi there, Now I'm facing error regarding running shell script via cron. The shell script which is required to get value from database. Below is the main part of shell script. #/bin/bash #connect to database(1) db2 connect to $database user xxxx using yyyy #set values from... (3 Replies)
Discussion started by: Rohan Kishibe
3 Replies

2. Shell Programming and Scripting

DB2 in awk

Hi, I want to retrieve the base table name for a table and replace the table with the view name in the file. I was trying to retrieve the base with the below db2 command but i am getting "1" as return value. Could you anyone please assist ? Table_name=system("db2 -x... (4 Replies)
Discussion started by: Nandy
4 Replies

3. UNIX for Advanced & Expert Users

Using xml to run db2 commands

Hi, Strange problem I'm having here and not sure what to do. I have here a xml that is supposed to execute the next value in the schema but it isn't do the job it's supposed to do. I'm not a dba or a developer so I'm sorry in advance if there are some things i don't understand. when we run... (5 Replies)
Discussion started by: techy1
5 Replies

4. Shell Programming and Scripting

Problem running awk script in Debian 6.0.2

Hello to all, May be some expert could help me. I have the below awk script that works correctly in Cygwin: awk -F\" 'FNR==NR && FNR>1 {gsub(",","",$5); N=$5;next} $10 in N && FNR>1 { Y=$8 Z=(N==$8)?"Yes:"No"; } END{ for(k in N) {print k,Y,N,Z?Z:"Not_Found"} }' file2 file1But when I... (11 Replies)
Discussion started by: Ophiuchus
11 Replies

5. Shell Programming and Scripting

Problem with running awk script in pbs file

Hi guys I have a problem with one module of my script. It's awk script running in pbs file - It's working when I make a call from pbs to separate awk only file like this but when I try to execute this code in pbs file it fails awk 'BEGIN { max = -1000; min = 1000 } { {$4 == "TCO"} ... (2 Replies)
Discussion started by: grincz
2 Replies

6. Shell Programming and Scripting

Running Sql scripts accross db2

Hi, I would be really thankful, if anyone could help me out with this,since i am very new to this shell scripting. I have 6 sql scripts that i am trying to run in unix across db2. i want the scripts to be executed as follows, script_1 should be executed first. Then... (4 Replies)
Discussion started by: jnimz
4 Replies

7. Shell Programming and Scripting

running db2 sql and exporting output from ksh scipt

Hi there, I am trying to write a shell script as root on AIX 5.3 where I change user to db2inst1, connect to our db2 database, run a sql select query and export the result of the query to a file. The code I have so far is as follows:- #!/usr/bin/ksh su - db2inst1 -c "db2 connect to... (0 Replies)
Discussion started by: candlino
0 Replies

8. UNIX for Advanced & Expert Users

Problem in running bash shell commands on HP-UX machine

Hello All, After login to the server we are explicitly calling /usr/local/bin/bash to activate bash shell properly. But since commands are not executing properly so I think it is not initialized well. I am facing following problems: 1) If I want to have a look on a particular file using tail... (6 Replies)
Discussion started by: abhishek0071
6 Replies

9. UNIX for Advanced & Expert Users

Problem in running an AWK script

Hi Everyone, I am required to write an AWK script that can be run from any directory. This script finds subscription rates for each subscriber at an interval of 10 mins. I want that just by copy pasting the whole script in shell prompt and giving the input arguments, script must work. Currenty... (4 Replies)
Discussion started by: rachana8p
4 Replies

10. UNIX for Dummies Questions & Answers

Problem running plsql & unix commands in 1 script

Hi, I need help again. When I run this shell script, it only runs the unld_date.sql piece and exits. How can I structure this to run all the way to the end? When I don't have the unld_date.sql piece in here, everything runs fine from the date compare piece all the way to the end. Thanks in... (5 Replies)
Discussion started by: siog
5 Replies
Login or Register to Ask a Question