Need inputs on UNIX script basics

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.

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:

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?

Post snippets of your $dml file and the required output you wish to see..

post #19 in

should help.