ksh program


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh program
# 8  
Old 01-10-2012
jay
The input content vary from one text file to other text file.
but the seniors remains same as i have explained in the first post.

out of complete text file, which may contain function or procedure we need to pick up only the complete select or update or delete statements in the file and check if we are using where clauses for each statement.
all the statements are separated by ';' except sub queries.

for example we can consider below statements as the content:-

select some text
(select some text(select some text)
where some condition)
where condition;

some statements some statements some statements;
update some text where condition;

some statements some statements;
delete some text where condition;

update some text condition;
delete some text condition;


for the last 2 statements above it should echo as false because it dose not have where clause.



Moderator's Comments:
Mod Comment Please use next time code tags

Last edited by vbe; 01-10-2012 at 07:44 AM..
# 9  
Old 01-10-2012
Addition of few lines .. Try with this ..
Code:
nawk '/^select/,/;/' infile | xargs | tr ';' '\n' > outfile
nawk '/^update/,/;/' infile | xargs | tr ';' '\n' >> outfile
nawk '/^delete/,/;/' infile | xargs | tr ';' '\n' >> outfile
grep . outfile > outfile1
while read line
do
        cnt=$(echo $line | tr ' ' '\n' | egrep "select|update|delete|where" | wc -l)
        echo "$line" | nawk -v var="$cnt" '{if(var%2==0){print $0" --> success"}else{print $0" --> fail"}}'
done < outfile1
rm outfile outfile1

# 10  
Old 01-10-2012
Code:
$ tr '\n' ' ' < input.txt | nawk -F\; '{for(i=1;i<=NF;i++){if($i!~/where/){print $i}}}'                                                             
 some statements some statements some statements
 some statements some statements
 update some text condition
 delete some text condition

---------- Post updated at 03:11 PM ---------- Previous update was at 03:09 PM ----------

Code:
$ tr '\n' ' ' < test.txt | nawk -F\; '{for(i=1;i<=NF;i++){if($i!~/where/){printf("%s -->False\n",$i)}}}'                                           
 some statements some statements some statements -->False
 some statements some statements -->False
 update some text condition -->False
 delete some text condition -->False

---------- Post updated at 03:11 PM ---------- Previous update was at 03:11 PM ----------

Code:
$ tr '\n' ' ' < test.txt | nawk -F\; '{for(i=1;i<=NF;i++){if($i!~/where/){printf("%s -->False\n",$i)}else{printf("%s --> Success\n",$i)}}}'        
select some text  (select some text(select some text)  where some condition)  where condition --> Success
 some statements some statements some statements -->False
 update some text where condition --> Success
 some statements some statements -->False
 delete some text where condition --> Success
 update some text condition -->False
 delete some text condition -->False

# 11  
Old 01-10-2012
Quote:
Originally Posted by itkamaraj
Code:
$ tr '\n' ' ' < test.txt | nawk -F\; '{for(i=1;i<=NF;i++){if($i!~/where/){printf("%s -->False\n",$i)}else{printf("%s --> Success\n",$i)}}}'        
select some text  (select some text(select some text)  where some condition)  where condition --> Success
 some statements some statements some statements -->False
 update some text where condition --> Success
 some statements some statements -->False
 delete some text where condition --> Success
 update some text condition -->False
 delete some text condition -->False

@kamaraj, for the highlighted line, the script has to throw fail scenario. Pls have a look ..
# 12  
Old 01-10-2012
we need to pick up only the complete select or update or delete statements in the file

all the statements are separated by ';' except sub queries.

so, i guess the code provided by me is correct
# 13  
Old 01-10-2012
@ manasa, Is kamaraj correct ??!!
# 14  
Old 01-10-2012
sorry for the late reply.. i am in a session. i wil test the code and post the result.

---------- Post updated at 05:43 PM ---------- Previous update was at 04:16 PM ----------

Kamraj,
the script is failing please see the below execution. also the script should not through success/fail for all the line it should pring success for only select/update/delete with where clauses and faile for only select/update/delete with out where clause.

UPDATE PARM_TABLE SET value = in_job_name||'_LOAD ' WHERE seq_no -->False
COMMIT -->False
END IF -->False




Quote:
Originally Posted by itkamaraj
Code:
$ tr '\n' ' ' < input.txt | nawk -F\; '{for(i=1;i<=NF;i++){if($i!~/where/){print $i}}}'                                                             
 some statements some statements some statements
 some statements some statements
 update some text condition
 delete some text condition

---------- Post updated at 03:11 PM ---------- Previous update was at 03:09 PM ----------

Code:
$ tr '\n' ' ' < test.txt | nawk -F\; '{for(i=1;i<=NF;i++){if($i!~/where/){printf("%s -->False\n",$i)}}}'                                           
 some statements some statements some statements -->False
 some statements some statements -->False
 update some text condition -->False
 delete some text condition -->False

---------- Post updated at 03:11 PM ---------- Previous update was at 03:11 PM ----------

Code:
$ tr '\n' ' ' < test.txt | nawk -F\; '{for(i=1;i<=NF;i++){if($i!~/where/){printf("%s -->False\n",$i)}else{printf("%s --> Success\n",$i)}}}'        
select some text  (select some text(select some text)  where some condition)  where condition --> Success
 some statements some statements some statements -->False
 update some text where condition --> Success
 some statements some statements -->False
 delete some text where condition --> Success
 update some text condition -->False
 delete some text condition -->False

---------- Post updated at 05:46 PM ---------- Previous update was at 05:43 PM ----------

Hi Jay,
with the above code out put is not getting displayed on the screen.
as your post says for all the lines in the file it is printing success or failure,
but it should print success/failure only for select,update and delete statements.

Quote:
Originally Posted by jayan_jay
@kamaraj, for the highlighted line, the script has to throw fail scenario. Pls have a look ..
---------- Post updated at 05:56 PM ---------- Previous update was at 05:46 PM ----------

Till end of the file search for all the select/update/delete statements(all statements end with Smilie only and perform as below
{
if number of “selects”= number of “where” before statement end by ; then success
else failure
if number of “update”=number of “ where” before ; of the statement then success
else failure
if number of “delete”=number of “ where” before statement end by; then success
else failure
}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing answers to external program from KSH

I have asked this before but I haven't had any luck so far getting this to work. I use RCS(revision control system). When it runs if I pass the value 'unlock' to $3 its reassigned to $unlock. When I run the command (rcs -u'version number' 'filename') ti will ask me 1-(Do you want to break the lock... (5 Replies)
Discussion started by: pjones006
5 Replies

2. Shell Programming and Scripting

Automating a Java program using KSH

Hi Guys, We have a java program that basically install updates to an existing software. The java program consist of several screens asking user for choices (please see below for a detailed example) *** Screen 1 *** Please choose the operation you want to perform: 1. Install new... (5 Replies)
Discussion started by: maddmaster
5 Replies

3. Shell Programming and Scripting

convert ksh to C program

Hi Guys...is there a way to convert a .ksh script to .C program..? (3 Replies)
Discussion started by: aggars
3 Replies

4. Shell Programming and Scripting

Invoke perl program from Ksh

Hi all, Can I invoke a perl script from Ksh script and pass parameters to the perl script. Please do help me.. thanks Maha (10 Replies)
Discussion started by: mahalakshmi
10 Replies

5. Shell Programming and Scripting

ksh program run with different results by different users

Hi, I wrote a ksh program on Unix. One thing I don't understand: some users run it with different results. I suspect it's either "cat" or "grep" command. Basically, with one group of user, the 'cat' or 'grep' command is not getting the data I need and that changed the result. Is the above... (2 Replies)
Discussion started by: cin2000
2 Replies

6. Shell Programming and Scripting

grep within ksh program

Hi, is there problem with grep command when using ksh? I had the below command: /usr/bin/grep \""$Mon $NewDD\"" /tmp/timemanager/intlog.$$ >> /tmp/timemanager/log.$$ 2>/dev/null when I run ksh in debug mode, this command can not grep anything even the data is in the file. + /usr/bin/grep... (3 Replies)
Discussion started by: cin2000
3 Replies

7. Shell Programming and Scripting

ksh program with password

Hi, I am looking for a way to utilize password when the ksh program is launched. What's the standard or best way to do it? Thanks for your help! (5 Replies)
Discussion started by: cin2000
5 Replies

8. Programming

parameters from my program in c to a .ksh script

hi.. this is my question: it is possible transfer parameters from my program written in C to a .ksh script? how can i do it? i have a program in C, what is called from a .ksh script, and i need what the C program returns some values (parameters) please, help me - any idea thanks ... (2 Replies)
Discussion started by: DebianJ
2 Replies

9. Shell Programming and Scripting

Adding entry into crontab in ksh program

Hi falks, I have the following ksh function ,which adding entry to crontab during ksh program running: { print "Go\c" >/dev/null 2>&1 print '0 0 * * * su - ias -c "/home/orca/core-${SCHEMA_NAME}/CLI/cleanup_BRMS.ksh"\c' >/dev/null 2>&1 print "\033:wq!" >/dev/null 2>&1 } | \crontab -e... (2 Replies)
Discussion started by: nir_s
2 Replies

10. UNIX for Advanced & Expert Users

date program in ksh

#Author : kkodava #!/usr/bin/ksh #Use of this program is You can findout the no of days & day of starting and ending dates #usage no_of_days startdate<yyyymmdd> enddate<yyyymmdd> syy=`echo $1|cut -c1-4` smm=`echo $1|cut -c5-6` sdd=`echo $1|cut -c7-8` eyy=`echo $2|cut -c1-4` emm=`echo... (1 Reply)
Discussion started by: krishna
1 Replies
Login or Register to Ask a Question