Answer the question
In order to leave comments, you need to log in
[SOLVED] Sed, or how to get value from INI file?
Good day.
The task is trifling, but something I was worn out. Bash script, parsing INI file. We get the contents of the section:
## 1. Get section content (text between '[%section_name%]' and next '[')
## 2. Remove lines, what begins on '['..
## 3. Remove empty lines
sectionContent=$(sed -n '/^\['$SectionName'\]/,/^\[/p' $mainVerFile | sed -e '/^\[/d' | sed -e '/^$/d');
param1=value1
param2=value2
param3=value3
## Parse data from passed content of ini section
function getValueFromINI() {
local sourceData=$1; local paramName=$2;
## 1. Get value "platform=%OUR_VALUE%"
## 2. Remove illegal characters
echo $(echo "$sourceData" | sed -n '/^'$paramName'=\(.*\)$/s//\1/p' | tr -d "\r" | tr -d "\n");
}
sectionContent=$(sed -n '/^\[GENERAL_SECTION\]/,/^\[/p' $pathToIniFile | sed -e '/^\[/d' | sed -e '/^$/d');
param1=$(getValueFromINI "$sectionContent" "param1");
param2=$(getValueFromINI "$sectionContent" "param2");
param3=$(getValueFromINI "$sectionContent" "param3");
Answer the question
In order to leave comments, you need to log in
You just need to find the line containing param2 from three lines and take the value?
If yes, then try this:awk -F '=' '/param2/ {print $2}'
Something like this:
IFS="="
while read -r name value
do
echo "Content of $name is ${value//\"/}"
done < filename
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question