awk/sed script to read values from parameter files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk/sed script to read values from parameter files
# 1  
Old 11-05-2008
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  
Old 11-05-2008
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  
Old 11-05-2008
Some of my parameters have space any idea how i can get round them since for loop treats space as a new line
# 4  
Old 11-05-2008
Quote the command:

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

Regards
# 5  
Old 11-05-2008
Thanks a lot everyone for the help it worked fine
# 6  
Old 11-06-2008
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  
Old 11-06-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script parameter with several values

Hi, On ksh I have to write a script tha I will run like this: ./myscript.ksh -param1 val1 val2 val3 .. -param2 xxx -param3 hgf Param1 will be an array: param1= ( val1 val2 val3 ..... ) How can I do that? It is not a homework!! Thank you. (1 Reply)
Discussion started by: big123456
1 Replies

2. UNIX for Beginners Questions & Answers

awk GSUB read field values from multiple text files

My program run without error. The problem I am having. The program isn't outputting field values with the column headers to file.txt. Each of the column headers in file.txt has no data. MEMSIZE SECOND SASFoundation Filename The output results in file.txt should show: ... (1 Reply)
Discussion started by: dellanicholson
1 Replies

3. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

4. Shell Programming and Scripting

'Couldn't read file' error in bash script with expect, sed and awk!

Ok, so I have a bash script with an embedded expect statement. Inside of the expect statement, i'm trying to pull all of the non-comment lines from the /etc/oratab file one at a time. Here's my command: cat /etc/oratab |sed /^s*#/d\ | awk 'NR==1'|awk -F: '{print \"$1\"}'|. oraenv Now,... (0 Replies)
Discussion started by: alexdglover
0 Replies

5. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

6. Shell Programming and Scripting

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (3 Replies)
Discussion started by: yerruhari
3 Replies

7. UNIX for Dummies Questions & Answers

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (1 Reply)
Discussion started by: yerruhari
1 Replies

8. UNIX for Advanced & Expert Users

Compare two files using awk or sed, add values in a column if their previous fields are same

Hi All, I have two files file1: abc,def,ghi,5,jkl,mno pqr,stu,ghi,10,vwx,xyz cba,ust,ihg,4,cdu,oqw file2: ravi,def,kishore ramu,ust,krishna joseph,stu,mike I need two output files as follows In my above example, each row in file1 has 6 fields and each row in file2 has 3... (1 Reply)
Discussion started by: yerruhari
1 Replies

9. UNIX for Dummies Questions & Answers

checking parameter values passed to script

Hi, I will pass 3 parameters for a script.I have to check the file name and create a new file name with time stamp. the parameters which i'm passing are /dir/stg/filename.txt /dir/path/head.txt /dir/path/tail.txt Now i have to check filename like : if it is a.txt i have to create... (2 Replies)
Discussion started by: ammu
2 Replies

10. Shell Programming and Scripting

Help!! Need script to read files and add values by lines...

Hi All, I really need your help. I am a begginner in shell script and I believe this is a very simple issue. I have in my directory, n-files, like 1.dhm, 2.dhm, 3.dhm. These files have 1 column with 1 value per line, like: 1.dhm ------ 10 20 30 40 50 2.dhm ------ 30 50 20 (3 Replies)
Discussion started by: dhuertas
3 Replies
Login or Register to Ask a Question