Parse config file and store the values in variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parse config file and store the values in variables
# 1  
Old 06-02-2010
Parse config file and store the values in variables

Hi,

I have a config file that has blank, commented lines. I need to escape commented lines, blank lines, parse the remaining lines and store them in variables or array.

the config file contains the following lines.

Code:
# config file
 
# Define Oracle User
ORA_USER=abcde
ORA_PASS=xyzabc
ORACLE_SID=def
 
# CSV file name
#FILENAME=U021999.csv
FILENAME=U025645.csv
#Log file
LOGFILE=Automation_log.xls
OUTPUTFILE=Output.xls

now I want to read the value "abcde" and store it in a variable. like wise I want to read all the values and store in an array.

How can I approach to get values those stored in an array.

thanks,
lakshmi chowdam.

Last edited by Franklin52; 06-02-2010 at 03:48 AM.. Reason: Please use code tags!
# 2  
Old 06-02-2010
you can get those values
Code:
 grep -v "#" input-file|awk -F= '/./{print $2}'

# 3  
Old 06-02-2010
Code:
grep -v "^$" filename | grep -v "^#"

# 4  
Old 06-02-2010
Quote:
Originally Posted by posix
you can get those values
Code:
 grep -v "#" input-file|awk -F= '/./{print $2}'

Hi Posix,

thanks for the quick reply.

I dont want to disply on the screen, insted i want to store in an array so that i can use further.

suppose i want to store in list array, and i can use as list[0] like that.

thanks,
lakshmi chowdam.
# 5  
Old 06-02-2010
MySQL

Hi,

try:

Code:
array=(`sed -n "s/^[^#].*=\(.*\)/\1/p" file)

to read the values into the array array.

Print the contents of the array with:
Code:
printf "%s\n" ${array[@]}

HTH Chris
# 6  
Old 06-02-2010
Yes ..Christoph has done the job for u.. thanks lot.
Output
Code:
[root@mftdev temp]#arr=(`grep -v "#" input_file|awk -F= '/./{print $2}'`)
[root@mftdev temp]# echo ${arr[*]}
abcde xyzabc def U025645.csv Automation_log.xls Output.xls

# 7  
Old 06-02-2010
Quote:
Originally Posted by Christoph Spohr
Hi,

try:

Code:
array=(`sed -n "s/^[^#].*=\(.*\)/\1/p" file)

to read the values into the array array.

Print the contents of the array with:
Code:
printf "%s\n" ${array[@]}

HTH Chris

Hi Chris,

thanks for the quick reply.

it is giving a syntax error: syntax error at line 34 : `(' unexpected

I am new to shell script, can you revert back with resolution.

Thanks,
lakshmi chowdam.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read record from the text file contain multiple separated values & assign those values to variables

I have a file containing multiple values, some of them are pipe separated which are to be read as separate values and some of them are single value all are these need to store in variables. I need to read this file which is an input to my script Config.txt file name, first path, second... (7 Replies)
Discussion started by: ketanraut
7 Replies

2. Shell Programming and Scripting

Parse a single line file and store value.

I have a single line file like this : Average Fragmentation Quotient : 3.084121 Now I want to store the value which comes after ":" i,e 3.084121 into a variable. And if this variable crosses above 6 i want to call another script... can any one help me on this... (7 Replies)
Discussion started by: Hyp_Todd
7 Replies

3. Shell Programming and Scripting

Need to parse lines in a file into two words and assign the values to two variables

For example, I have a file with below lines containing VOB tags and VOB paths. * /vobs/fts/FTSUSM20_VOB /ccvobsslx01/projects/vobs/eml/FTSUSM20_VOB * /vobs/fts/FTS20_VOB /ccvobsslx01/projects/vobs/eml/FTS20_VOB * /vobs/pmv/PMS_VOB /ccvobsslx01/projects/vobs/cpm/_/PMS_VOB *... (4 Replies)
Discussion started by: senthilkc
4 Replies

4. UNIX for Dummies Questions & Answers

Parse or cut concat variables to individual values

Hello I need to pass some environment parameters to a datastage job and am getting an error when trying to send the complete concatinated variable. I have decided to parse out just the values and send as parameters but am struggling to find the best way to do this (actually I am not very... (3 Replies)
Discussion started by: LynnC
3 Replies

5. Shell Programming and Scripting

Parse config file data to script variable

I have a script with few pre defined variables. Also have a config file. Something like this. # config file # Define Oracle User MOD1_TAG=abcde MOD2_TAG=xyzabc MOD3_TAG=def I need to parse the config file and have each of the value copied to different variables. Please suggest what... (1 Reply)
Discussion started by: souryadipta
1 Replies

6. Shell Programming and Scripting

Parse text file in shell & store to variable

Hi, I need to parse a simple text file like below and store the word that starts with BR* to a variable say $BRno. I need to do this in sh script. NOTE: the length of the numbers following BR is in constant. And there is only 1 BRXXX in a file at a given time. .txt file: BR276828... (1 Reply)
Discussion started by: script2010
1 Replies

7. Shell Programming and Scripting

sed command to parse Apache config file

Hi there, am trying to parse an Apache 'server' config file. A snippet of the config file is shown below: ..... ProxyPassReverse /foo http://foo.example.com/bar ..... ..... RewriteRule ^/(.*) http://www.example.com/$1 RewriteRule /redirect https://www.example1.com/$1 ........ (7 Replies)
Discussion started by: jy2k7ca
7 Replies

8. Shell Programming and Scripting

script to store comma separated values in different variables

Hello friends, I need ur help.I want to write a script. The script should read contents from a file namely xyz. e.g xyz abcd,1234,efgh,7854378 dhnsa,dsakjkdl,43432,ZXDsa the script should store comma (,) seperated values in different variables. Once pointer will reach end of line (\n), it should... (1 Reply)
Discussion started by: akhtar.bhat
1 Replies

9. UNIX for Dummies Questions & Answers

trouble using read to store values in variables from command output

I know there are caveats about using read in pipelines because read is treated by a subshell. I know this but I can't think of any way to accomplish this regardless, I'm still a rookie. I hope somebody will be able to interpret what it is that I'm trying to accomplish and correct me. ... (2 Replies)
Discussion started by: ProGrammar
2 Replies

10. Shell Programming and Scripting

How to parse config variables from external file to shell script

How do i use a config.txt to recursively pass a set of variables to a shell script eg my config.txt looks like this : path=c://dataset/set1 v1= a.bin v2= b.bin path=c://dataset/set2 v1= xy.bin v2= abc.bin .................. and so on . and my testscript : (2 Replies)
Discussion started by: pradsh
2 Replies
Login or Register to Ask a Question