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.

# 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.

you can get those values

 grep -v "#" input-file|awk -F= '/./{print $2}'
grep -v "^$" filename | grep -v "^#"

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.

Hi,

try:

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

to read the values into the array array.

Print the contents of the array with:

printf "%s\n" ${array[@]}

HTH Chris

Yes ..Christoph has done the job for u.. thanks lot.
Output

[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

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.

There is a "`" missing at the end, try:

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

Hi All,

Please try the below steps:

grep -v "^[ ]$" c.cfg | grep -v "^#" | awk -F"=" ' { print $2 }' > t.log
 
 while IFS= read -r line
do
     array[$i]=$line
     (( i++ ))
 done < t.log

 for i in "${array[@]}"
 do
     echo $i
 done

Thanks,
Deepak