But I'm worried if the sections in the config file will switch and the order not preserved ... then the grep -mX and tail will not give me the proper value for the section/parameter I want.
I want to read this values and later to write them back in the new config file with:
sed -e "/\[Billing\]/,/^[^#][:space:]*ProcessorsNumber =/ s-\(^[^#][:space:]ProcessorsNumber = \)\([^#]\)-\1$BILLPROCESSORSNUMBER-1" \
This sed works.
So it is alll about how to read correct from the file.
That's why I asked for a real sample of your input file.
Most of us are hard-working professionals, we like to help but we have more to do than answering wrong formulated questions.
My mistake for not explaining the entire pb:
The file.cfg
[GetAuthRequest]
Plugin1 = Billing
Plugin2 = Preview
Plugin4 = AnticipateResponse
Plugin5 = Plugins
[BillingInfoReportRequest]
Plugin1 = Plugins
Plugin2 = Statistics
Plugin5 = Bookmarks
Plugin6 = Preview
Plugin7 = Billing #text text
[Billing] #texttex
LocalIPAddress = 192.168.1.116
Another Parameter = xxx
ProcessorsNumber = 1
[Plugins]
ProcessorsNumber = 2 #text text
LocalIPAddress = 192.168.2.116
[Statistics] #text text #text text
LocalIPAddress = 192.168.3.116 #text text
ProcessorsNumber = 1
So the section NAME can be present for more than once in the file.cfg but the section [NAME] only once.
This is the result after running you command:
[bianca@skynet bianca]# a=`awk -v file=file.cfg awk '/Statistics/{f=1;while($1 != "ProcessorsNumber"){getline}}f{print $3;exit}' file`
awk: cmd. line:2: fatal: cannot open file `/Statistics/{f=1;while($1 != "ProcessorsNumber"){getline}}f{print $3;exit}' for reading (No such file or directory)