Need inputs on UNIX script basics


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need inputs on UNIX script basics
# 1  
Old 01-12-2011
How to extract entire WHERE clause from a SQL using UNIX

Hi UNIX Gurus,

I have a SQL utility which fires DML statements against DB2 tables. Logic is to identify DML statements, put it into a file ($dml) and execute the job.

DML file can have more than 1 DML statements....but all of 1 type at a time.....either all UPDATE or all DELETE.

Job first check the count which is the records impacted by each DML statement. This was a pre-requisite condition.

So I used following code. It works fine for normal UPDATE/DELETE queries, but not fetching exact WHERE clause where we have in-queries.


Code:
sed 's/.*\([wW][hH][eE][rR][eE] .*$\)/\1/' $dml > $temp1 --> Selecting the WHERE clause of the DML mentioned in file $dml and put it in a temp file, temp1
sed "s/[wW][hH][eE][rR][eE]/select count(*) from $SCH.$TBL where/" $temp1 > $ddl --> use the WHERE clause mentioned in the temp file temp1 and creates SELECT COUNT(*) statement and put it in $ddl file
rm $temp1--> Remove temp file temp1


Example of DML statement for which I was executing it but it was not working correctly:

Code:
UPDATE 
<TABLE_NAME> 
SET 
<FIELD_NAME> = VALUE 
WHERE 
CONDITION_1 AND 
CONDITION_2 = (SELECT FIELD_NAME FROM TABLE_NAME WHERE CONDITION_XYZ);

P.S. - Format mentioned in above query is not fixed. It may be mentioned in 1 line or in multiple lines just like above. Also it can have more than 1 DML statement in input file.

Thanks in advance....
Beginner in UNIX

---------- Post updated at 02:13 PM ---------- Previous update was at 12:56 PM ----------

Is there anyone who can help me in resolving this?

Last edited by ustechie; 01-12-2011 at 04:07 PM..
# 2  
Old 01-13-2011
Post snippets of your $dml file and the required output you wish to see..
# 3  
Old 01-13-2011
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX Shell Script to Remove MongoDB Document-Based on Many inputs

Here I am in a position to write a Unix Shell script(.sh) to remove MongoDB collection documents. I know how to remove based on a condition like below and it works for me. eval 'db.Collection.remove({TimeStamp:{$lte: "'$var'"}}) But I need to change the remove statement based on a new parameter... (1 Reply)
Discussion started by: senthilmadhanT
1 Replies

2. UNIX for Dummies Questions & Answers

UNIX Basics about shell and editors and default settings

Hi all, I have 3-4 years of experience working on unix environment. I am not a beginner, but unix is not my primary skill set. I am very good at awk programming and doing many of my tasks very well, really very weak on basics. I moved to a new job recently and the settings there are driving me... (5 Replies)
Discussion started by: ysvsr1
5 Replies

3. UNIX for Dummies Questions & Answers

UNIX basics

Hi, I am new to Unix. can you explain in brief with examples what is variable, what is argument and what is parameter? i searched a lot on other forums but not able to find a appropriate answer. thanks in advance!! (3 Replies)
Discussion started by: 21laps
3 Replies

4. UNIX for Dummies Questions & Answers

How to send keyboard inputs toa UNIX command executed from a shell script?

I have a unix command that prompts for 'y'. How do I run this from my shell script? (4 Replies)
Discussion started by: Sree10
4 Replies

5. UNIX for Dummies Questions & Answers

UNIX Basics

Hello, 1) I am trying to get involved in UNIX for educational purposes so I have installed the latest Ubuntu edition 12.04. Do you know another package that I could use it instead for educational purposes? 2)What is the difference between "~$" and "/$" (it comes with cd / and cd ~) .The... (1 Reply)
Discussion started by: Iwn
1 Replies

6. Shell Programming and Scripting

Just started using UNIX, im at the basics and my scripts broken.

echo "Hi $username, guess what my favourite colour is!" count=0 while ] do read colour if then $count=1 echo "See ya later!" elif then $count=1 echo "You guessed correctly! Great job!"... (6 Replies)
Discussion started by: solomonsnare
6 Replies

7. AIX

UNIX/AIX Performance Tuning = some basics please

Hi all, From Googling, I found that the basics used for troubleshooting UNIX/AIX performance issues are commands like vmstat, iostat and sar. I believe these are generic commands regardless of what UNIX flavour is in used, only difference being is the format of the output. In a real case... (2 Replies)
Discussion started by: newbie_01
2 Replies

8. UNIX for Dummies Questions & Answers

Unix Basics

Hey, you said this forum was for Dummies, so don't blame me for the following! :D My whole "web building" life, I've had my sites hosted in one for or another. Lately, I've gotten into PHP and MySQL and, of course, those are also hosted for me. But lately, I've been thinking of using PHP and... (2 Replies)
Discussion started by: cap97
2 Replies

9. UNIX for Dummies Questions & Answers

UNIX Basics

I want to learn UNIX, but I have a few questions. If anybody could help me out I'd greatly appreciate it. First, I've decided I'm going to use Red Hat Linux and I've been told the only difference between 7.2 and the Professional (besides the price), is the tech support that you'll receive. Is... (2 Replies)
Discussion started by: paulSF
2 Replies
Login or Register to Ask a Question