How to add control statement?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to add control statement?
# 1  
Old 07-14-2010
Bug How to add control statement?

Hi everyone,
I have a script in which i need to add some codes.Right now my scripts takes table name from i/p file data.txt then matches it with data in another file table.if table exists then it searches for line cotaining "add" and extract column from there.Now i need to do additional part in it.That is when script search for line having "ADD" then before addition of columns from that line it should check that whether "constraint" word exist after "add" or not.If "constraint exists then need not to operate further on that line.

Code:
!/bin/sh
#read.sh
sed -n '/ALTER/,/;/p' new.txt > data.txt
sed '/;/ a\
        ' data.txt > data.ex
/usr/xpg4/bin/awk '
NR==FNR {
tbl[$1]++;
next;
}
/ALTER TABLE/ {
tbl_name = $3;
if (tbl_name in tbl)
        getcols = 1
   else getcols = 0;
   next;
}
 
getcols != 1 {
 printf "%-12s\t %-12s\n" , tbl_name , "NOT FOUND";
next ;
}
/^ADD/,/;[[:space:]]*$/ {
f = ($1 ~ /^ADD/ ? 3 : 1);
sub(/).*/, ")", $(f+1));
printf "%-12s\t %-12s\t %s\t %s\n" , tbl_name, $f, $(f+1) , "NOT NULL";
 
}
 
' table data.ex > result
echo "
1i
"`grep "DDCF No." new.txt`"\n
.
wq
" | ex -s result
cut -d"|" -f3 result | sort -u | tee result1


Please help me with that.
Thanks

Last edited by alisha; 07-16-2010 at 03:40 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. Shell Programming and Scripting

How to add printf statement in awk command?

hi all i need to add the prinf statement in awk command for the converted comma separated output.... below is my code : Code Credits :RudiC awk -F, 'NF==2 {next} {ITM=$1 AMT=$2+0 CNT=$3+0 TOTA+=$2 ... (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

3. Shell Programming and Scripting

How to add if statement in expect script

Hi, I am new to expect script and I am having difficulty in adding an if statement into a expect FTP login script. Here is the code: #!/usr/local/bin/expect -f set FTP_SITE set FTP_USER set FTP_PASS set FTP_FILE spawn ftp match_max 100000 expect -exact "ftp> " send -- "open... (1 Reply)
Discussion started by: jrcai
1 Replies

4. Linux

How to add ^M (control M) in Linux

I would like to add ^M (CTRL V CTRL M) to all lines of the file. This is easy using unix2dos command in SunOS, unix2dos commands appends ^M for all the lines in SUnOS but I dont see the same beahaviou in Linux. My files on Linu'x to be added with ^M at the end of each line. is there any... (3 Replies)
Discussion started by: LinuxLearner
3 Replies

5. Linux

Modify expect script with control statement

Ok, so I have this script that was provided to me by one of the posters on this site. This script seems to be perfect. However, since this is a telnet script, i need to add an if then statement to it but dont know how to do it. What i want to do is to have this script spit out a certain... (3 Replies)
Discussion started by: SkySmart
3 Replies

6. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

7. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

8. Shell Programming and Scripting

Expect control statement

I am using expect I dont know tcl but trying to use a control statement to send requests from an input file - dont know what I am doing to be honest as I dont know tcl and dont use expect too much... Any help? See below Basically I am opening a telnet session to a server which works fine... (2 Replies)
Discussion started by: frustrated1
2 Replies

9. UNIX for Advanced & Expert Users

New to Control-M

Hi, I am very new to Control-M . If anywone know about the global conditions in Control-M. (5 Replies)
Discussion started by: oraclenerd
5 Replies

10. UNIX for Dummies Questions & Answers

Add Image Size (W-H) to a UNIX statement

I am using a counter on Comcast and I have it working OK. What I need to do is to add the width and height of 'counter.gif'. Below is the statement I am using: &richportal is the counter name on the Comcast Server. EX: w=10px h=10px <img src="/cgi-bin/counter.gif?&richportal"> Thanks: Barry (0 Replies)
Discussion started by: barrie
0 Replies
Login or Register to Ask a Question