![]() |
|
|
|||||||
| Home | Forums | Register | Rules & FAQ | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. Shell Script Page. |
Other UNIX.COM Threads You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to handle multiple rows in a file | ksmbabu | Shell Programming and Scripting | 2 | 05-14-2008 09:44 PM |
| extract multiple sections of file | rgentis | Shell Programming and Scripting | 6 | 03-24-2008 07:51 PM |
| flexible sed command needed to handle multiple input types | SiftinDotCom | Shell Programming and Scripting | 2 | 03-19-2008 12:39 PM |
| extract multiple sections of a file | rgentis | UNIX for Advanced & Expert Users | 1 | 03-18-2008 04:40 PM |
| How to handle the Multiple Rows in the Database | hsekol | Shell Programming and Scripting | 2 | 03-05-2007 04:51 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
| Forum Sponsor | ||
|
|
|
||||
|
Config File example
[Billing]
LocalIPAddress = 192.168.1.116 ProcessorsNumber = 1 [Plugins] LocalIPAddress = 192.168.2.116 ProcessorsNumber = 2 [Statistics] LocalIPAddress = 192.168.3.116 ProcessorsNumber = 1 I manage to read like this: BILLPROCESSORSNUMBER=`grep -m1 '^[^#][:space:]*ProcessorsNumber' $OLD_CFG | awk -F" = " '{print $2}' |tail -1` PLUGINPROCESSORSNUMBER=`grep -m2 '^[^#][:space:]*ProcessorsNumber' $OLD_CFG | awk -F" = " '{print $2}' |tail -1` STATPROCESSORSNUMBER=`grep -m3 '^[^#][:space:]*ProcessorsNumber' $OLD_CFG | awk -F" = " '{print $2}' |tail -1` 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. Thanks Bianca |
|
|||
|
Try this:
Code:
BILLPROCESSORSNUMBER=`awk -v file=$OLD_CFG '/Billing/ {getline;getline;print $3}' file`
PLUGINPROCESSORSNUMBER=`awk -v file=$OLD_CFG '/Plugins/ {getline;getline;print $3}' file`
STATPROCESSORSNUMBER=`awk -v file=$OLD_CFG '/Statistics/ {getline;getline;print $3}' file`
|
|
||||
|
This doesn't work because the config file has many lines (text and other parameters) in between and the parameters position is not fixed.
[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 |
||||
| Google UNIX.COM |