help on script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help on script
# 1  
Old 09-08-2008
help on script

I have around 200 tables need to check the following column sequence instead of checking manually every table ,if sequence is different ,
it should return the table name so that I can check that table and re-arrange the sequence.Any help it should be greatful.


NEW_Cd
Factor_Desc
Tab_name


Tab1.txt

CREATE SET TABLE xx1 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
SECT_Cd CHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
NEW_Cd CHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
Factor_Desc VARCHAR(250) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
Tab_name VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC,
Code1 VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC,
Start_Dt DATE FORMAT 'YYYY-MM-DD' NOT NULL
)
PRIMARY INDEX ( Calculation_Factor_Cd )
;


CREATE SET TABLE xx2 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
NEW_Cd CHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
Tab_name VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC,
Factor_Desc VARCHAR(250) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL,
Code1 VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC,
Start_Dt DATE FORMAT 'YYYY-MM-DD' NOT NULL
)
PRIMARY INDEX ( Calculation_Factor_Cd )
;




Thanks,
MR
# 2  
Old 09-08-2008
Code:
awk '
/^CREATE SET TABLE/ { tablename = $4 }
(/^Factor_Desc/ && last != "NEW_Cd") ||
 (/^Tab_name/ && last != "Factor_Desc" ) { printf "Error: %s\n", tablename }
{ last = $1 }
' "$FILE" | uniq

##

# 3  
Old 09-09-2008
I am getting the below error when executing the below one

awk ' /^CREATE SET TABLE/ { tablename = $4 } (/^DBS_ECC_Code_Table_Name/ && last != "DBS_New_Cd") || (/^Tab_name/ && last !"DBS_ECC_Code_Table_Name" ) { printf "Error: %s\n", tablename } { last = $1 } ' a.txt | uniq


syntax error The source line is 1.
The error context is
/^CREATE SET TABLE/ { tablename = $4 } (/^DBS_ECC_Code_Table_Name/ && last != "DBS_New_Cd") || (/^Tab_name/ && last >>> ! <<< "DBS_ECC_Code_Table_Name" ) { printf "Error: %s\n", tablename } { last = $1 }
awk: Quitting
The source line is 1.

Thanks,
MR
# 4  
Old 09-09-2008
Hi

Please ignore my previous post .When executing the below one ,Its not giving any result even if sequence is not in order


awk '/^CREATE SET TABLE/ { tablename = $4 }(/^Factor_Desc/ && last != "NEW_Cd") ||(/^Tab_name/ && last != "Factor_Desc" ) { printf "Error: %s\n", tablename }{ last = $1 }
' a.txt | uniq

Thanks,
MR
# 5  
Old 09-09-2008
Quote:
Originally Posted by mohan705
Hi

Please ignore my previous post .When executing the below one ,Its not giving any result even if sequence is not in order


awk '/^CREATE SET TABLE/ { tablename = $4 }(/^Factor_Desc/ && last != "NEW_Cd") ||(/^Tab_name/ && last != "Factor_Desc" ) { printf "Error: %s\n", tablename }{ last = $1 }
' a.txt | uniq

First, when posting code, please enclose it in CODE tags.

Second, do not put your code all on one line. It makes it hard to read.

Third, the above script works for me when used with the data you supplied.
# 6  
Old 09-09-2008
Hi cfajohnson

Sorry it is my mistake ,its working fine.Thanks for your great help .


I have one more query ,I want replace null value of end_dt field to default value "1999-01-01' in all my insert scripts(It has around 200 scripts).Any help it should be greatful.


insert into PRD_TYPE
(
Period_Cd,
Period_Desc,
Ind1,
IND2,
Start_Dt,
End_Dt
)
select
Period_Cd,
Period_Desc,
NULL,
NULL,
date '1900-01-01' as START_DT,
NULL
from PRD_TYPE_2;


I am expecting the below o/p


insert into PRD_TYPE
(
Period_Cd,
Period_Desc,
Ind1,
IND2,
Start_Dt,
End_Dt
)
select
Period_Cd,
Period_Desc,
NULL,
NULL,
date '1900-01-01' as start_dt,
date '1999-01-01' as end_dt
from PRD_TYPE_2;

Thanks
MR
# 7  
Old 09-10-2008
Quote:
Originally Posted by mohan705

insert into PRD_TYPE
(
Period_Cd,
Period_Desc,
Ind1,
IND2,
Start_Dt,
End_Dt
)
select
Period_Cd,
Period_Desc,
NULL,
NULL,
date '1900-01-01' as START_DT,
NULL
from PRD_TYPE_2;


I am expecting the below o/p


insert into PRD_TYPE
(
Period_Cd,
Period_Desc,
Ind1,
IND2,
Start_Dt,
End_Dt
)
select
Period_Cd,
Period_Desc,
NULL,
NULL,
date '1900-01-01' as start_dt,
date '1999-01-01' as end_dt
from PRD_TYPE_2;

Thanks
MR

I think its line number 16

try this

linenumber=16
sed -i "${linenumber}s/\<NULL\>/date '1999-01-01' as end_dt /g" file-name

Thanks,
Bash
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question