The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regarding Shell Scripting anilkarikkandar UNIX for Dummies Questions & Answers 3 11-19-2006 08:26 PM
HELP PLS!! Shell Scripting!! Mary_xxx Shell Programming and Scripting 9 09-16-2006 03:52 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 05:12 AM
something else on shell scripting master_6ez Shell Programming and Scripting 1 11-21-2004 07:42 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-09-2006
Registered User
 

Join Date: Mar 2006
Posts: 18
Help on SED AWK in shell scripting

Hi,
I have a script abc.sql which contains a word 'timestamp'.
I have another script xyz.txt genrated everyweek, which has a new timestamp value every week.
How do I replace the word 'timestamp' in script abc.sql with the value mentioned in the script xyz.txt, so that I can run the script abc.sql with the a new timestamp value every week.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-09-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
You could a) pass a parameter to your SQL script as it's executed or b) sed 's/oldtimestamp/newtimestamp/' < oldsqlscript > newsqlscript if you want to do it the hard way.
Reply With Quote
  #3 (permalink)  
Old 03-09-2006
Registered User
 

Join Date: Mar 2006
Posts: 18
The thing is that the value changes every week. So if I write a script with that sed command I ineed to include a variable in the command and to do that I need to include the " character. If I do that then I cannot execute the command so right now in a diff script I echo the sed command with the variable and pass it to a new script which actually runs the sed command. This is the only way I can do it now. I wanted an easier way.
and more over the abc.sql script cannot have any variables because I dont execute that as s shell script.
Reply With Quote
  #4 (permalink)  
Old 03-09-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Database engines typically have command processors like Oracle's sqlplus.

sqlplus allows for arguments to be passed so that copies of SQL scripts don't have to be created every time a value changes.
Code:
sqlplus un/pw @abc.sql 20060309
The abc.sql script might look like this:
Code:
INSERT INTO sometable (columna, columnb, datecolumn)
VALUES (value1, value2, TO_DATE('&1', 'YYYYMMDD'));
COMMIT;
Note: &1 is sqlplus' parameter name.

If you have an SQL script and if you are creating a copy of it with a new value as you indicate then it follows that you are attempting to execute the SQL through some utility. The utility that executes the SQL should allow you to pass parameters. Oracle sqlplus, Sybase's/Microsoft's isql, et. al. all allow for this capability. I don't use MySQL or DB2 but I would be surprised if they don't allow for parameters.

Last edited by tmarikle; 03-09-2006 at 10:46 AM.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:33 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0