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
checking parameter values passed to script ammu UNIX for Dummies Questions & Answers 2 10-05-2007 12:35 PM
Help!! Need script to read files and add values by lines... dhuertas Shell Programming and Scripting 3 09-15-2007 11:14 PM
Read from file as script parameter vmaxx Shell Programming and Scripting 2 06-25-2005 10:30 AM
Korn Shell Script - Read File & Search On Values run_unx_novice Shell Programming and Scripting 2 06-15-2005 07:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
  #1 (permalink)  
Old 11-05-2008
rajan_san rajan_san is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 39
awk/sed script to read values from parameter files

Hi,

I am writing a shell program that executes a lot of Oracle SQL Files on different databases based on the enviroment setting value. I am trying to design a parameter file where i can store the environment values for all the databases in the below format

Environment File

File Name oraenv

# /* DB1 */
ORACLE_SID=DB1
ORACLE_BASE=
ORACLE_HOME=
PATH=
LD_LIBRARY_PATH=
.
.
Other Parameters
# /* End */
# /* DB2 */
ORACLE_SID=DB2
ORACLE_BASE=
ORACLE_HOME=
PATH=
LD_LIBRARY_PATH=
.
.
Other Parameters
# /* End */
# /* DB3 */
ORACLE_SID=DB3
ORACLE_BASE=
ORACLE_HOME=
PATH=
LD_LIBRARY_PATH=
.
.
Other Parameters
# /* End */

Master Script <-- Main Program that uses these parameters

File Name actions.sh

When the script is executed as ./actions,sh DB1 i want this to read all the parameters related to DB1 from the oraenv written between the pattern below
# /* DB1 */
.
...
..
# /* End */

create "export ORACLE_SID .." etc...

Any ideas of how best we can do this....

Thanks and Kind Regards,
Rajan.S
  #2 (permalink)  
Old 11-05-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,272
You could do something like for example:
Code:
DB=DB1
for LINE in `sed -n '/ '${DB}' /,/ End /p' infile| grep -v ^#`; do
     export "${LINE}"
done
Where instead of variable DB you can use $1 for input.
  #3 (permalink)  
Old 11-05-2008
rajan_san rajan_san is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 39
Some of my parameters have space any idea how i can get round them since for loop treats space as a new line
  #4 (permalink)  
Old 11-05-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,302
Quote the command:

Code:
for LINE in "`sed -n '/ '${DB}' /,/ End /p' infile| grep -v ^#`"; do
Regards
  #5 (permalink)  
Old 11-05-2008
rajan_san rajan_san is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 39
Thanks a lot everyone for the help it worked fine
  #6 (permalink)  
Old 11-06-2008
rajan_san rajan_san is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 39
One issue that i am facing with the above code is if i have the following line in my parameter file like

Parameter File content

infile

# /* DB1 */
ORACLE_HOME=/temp
OH=$ORACLE_HOME
# /* End */

The below command

for LINE in `sed -n '/ '${DB}' /,/ End /p' infile| grep -v ^#`; do
export "${LINE}"
done

works great when it reads line one that is ORACLE_HOME is set to /temp
but i expect it to set OH=/temp also but OH gets set to $ORACLE_HOME.Basically it does not translate the $sign read from the parameter file. Any ideas please
  #7 (permalink)  
Old 11-06-2008
rajan_san rajan_san is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 39
I was able to get through this issue using the eval option

for LINE in `sed -n '/ '${DB}' /,/ End /p' infile| grep -v ^#`; do
eval `echo "export " ${LINE}`
done

Thanks
Rajan
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 07:57 PM.


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