help on script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help on script
# 8  
Old 09-10-2008
Or if the line number might vary, but it's the NULL alone on a line immediately after the START_DT line,

Code:
sed -i '/as START_DT/,/^NULL$/s/^NULL$/'"date '1999-01-01' as end_dt /" filename

If your sed doesn't support the -i option, you will need to store the results in a temporary file and move it back on top of the original file.
# 9  
Old 09-10-2008
Hi era,
Its not working .(NULL alone on a line immediately after the START_DT line in all my scripts)

sed '/as START_DT/,/^NULL$/s/^NULL$/'"date '1999-01-01' as end_dt /" c.txt

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;

Thanks,
MR
# 10  
Old 09-10-2008
Then I guess the NULL is not really alone on the line; do you have spaces on either side? Fixing that is a trivial exercise. Or use the regex suggested earlier by learnbash, i.e. \<NULL\> instead of ^NULL$
# 11  
Old 09-10-2008
Hi Era,

Sorry ,Its working (spaces infornt Null and removed ^ before null).Thanks for your help.How can do it same thing in perl



sed '/as START_DT/,/NULL$/s/NULL$/'"date '1999-01-01' as end_dt /" c.txt

Thanks,
MR
# 12  
Old 09-10-2008
In Perl, the line range operator is different -- actually there are two different operators to choose from, ... or .. (I leave it to you to figure out from the documentation what their differences are).

Code:
perl -pe 'if (/as START_DT/ .. /NULL$/) { s/NULL$/'"date '1999-01-01' as end_dt / }" c.txt

Or in Perl, you can do matching across line boundaries with -0777:

Code:
perl -0777 -pe 's/(as START_DT,\s*\n\s*)NULL\n/$1'"date '1999-01-01' as end_dt\n/" c.txt

There is also a s2p script which ships with the Perl distribution which automatically translates sed scripts to Perl scripts (although the end result is not always particularly elegant, and sometimes even wrong, I hear).
# 13  
Old 09-10-2008
Hi Era,

Thanks for your great help .

Thanks,
MR
# 14  
Old 09-11-2008
Hi cfajohnson ,

I am checking the following sequence in my file,there are 3 tables last 3 columns having similar sequnce but
when calling the below script its not suppose to give any table name but its giving two table name.Please help


Standardized_Ind
New_Cd
Table_Name



FILE=$1
awk ' /^CREATE SET TABLE/ { tablename = $4 }
(/^Table_Name/ && last != "Standardized_Ind") ||
(/^New_Cd/ && last != "Table_Name" )
{ printf "Error: %s\n", tablename } { last = $1 } ' "$FILE" | uniq


calling unix script


#ab.sh b.txt

Error: XX
Error: XX2


b.txt

CREATE SET TABLE XX ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
Categ_Cd VARCHAR(10) CHARACTER ,
Categ_Desc VARCHAR(250) ,
Standardized_Ind CHAR(1) ,
New_Cd VARCHAR(20) ,
Table_Name VARCHAR(100) ) ;

CREATE SET TABLE XX1 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
Categ_Cd1 VARCHAR(10) ,
Categ_Desc1 VARCHAR(250) ,
Standardized_Ind CHAR(1) ,
New_Cd VARCHAR(20) ,
Table_Name VARCHAR(100) ) ;

CREATE SET TABLE XX2 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT
(
Financial_Asset_Categ_Cd VARCHAR(10) ,
Financial_Asset_Categ_Desc VARCHAR(250) ,
Standardized_Ind CHAR(1) ,
New_Cd VARCHAR(20) ,
Table_Name VARCHAR(100) );

Thanks,
MR
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