The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-20-2006 12:26 AM
HELP PLS!! Shell Scripting!! Mary_xxx Shell Programming and Scripting 9 09-16-2006 06:52 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 08:12 AM
something else on shell scripting master_6ez Shell Programming and Scripting 1 11-21-2004 11:42 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-09-2006
kaushys kaushys is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 22
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.
  #2 (permalink)  
Old 03-09-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
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.
  #3 (permalink)  
Old 03-09-2006
kaushys kaushys is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 22
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.
  #4 (permalink)  
Old 03-09-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
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 02:46 PM..
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0