odium74
1
hi people,
i'm having a hard time trying to extract a list of vars delimited by section inside a ini file ...
let's consider this ini file :
; config file
[GENERAL]
DESC = "channel synchro TGG01"
DMM_VER = DMM23
PATH_FIFO = /users/tgg00/fifo
[EMITTER]
QRT = BTS01.TGG.01.2
MODE_TRACE = O
now , inside a ksh batch i try to extract vars defined exclusively inside the GENERAL section ... using sed ...
sed -ne '/\[GENERAL\]/,/\[EMITTER\]/ p' < $my_ini_file
with this method the output is :
[GENERAL]
DESC = "channel synchro TGG01"
DMM_VER = DMM23
PATH_FIFO = /users/tgg00/fifo
[EMITTER]
how can i remove the section names [] from the output ?
thank you for any help !
birei
2
Hi odium74,
One way:
$ sed -ne '/\[GENERAL\]/,/\[EMITTER\]/ { /^\(\[\|\s*$\)/ b ; p }' infile
DESC = "channel synchro TGG01"
DMM_VER = DMM23
PATH_FIFO = /users/tgg00/fifo
Regards,
Birei
zaxxon
3
Another one with awk:
# awk '/^\[GENERAL/ {x=1; next} /^\[/ {x=0} x==1 && !/^[\t ]*$/' infile
DESC = "channel synchro TGG01"
DMM_VER = DMM23
PATH_FIFO = /users/tgg00/fifo
odium74
4
hello,
firstly thank you for replying !
i tried your solution, but there must be some kind of syntax problem, or
maybe due to the sed version of my machine ...
i'm using HP-UX B.11.11 ..
sed -ne '/\[GENERAL\]/,/\[EMISSION\]/ { /^\(\[\|\s*$\)/ b ; p }' < $my_ini_file
output error :
sed: There are too many '{'.
any alternative ?
thank you
birei
5
Sorry, I can't help much with that. It works in my system:
$ sed --version | head -1
GNU sed versi�n 4.2.1
I can guess a miss of a ';' just before or after last '}', but it's a shot in the dark. Try it. Else you will have zaxxon's awk solution.
$ sed -ne '/\[GENERAL\]/,/\[EMITTER\]/ { /^\(\[\|[ ]*$\)/ b ; p; };' infile
Regards,
Birei.
ctsgnb
6
Since no list has been opened (the opening square brackets are escaped),
no escape is needed for the closing bracket : it is taken as litteral.
When already inside a list, the opening square bracket is taken as litteral so : no escape needed either
sed -n '/\[GENERAL]/,/\[EMITTER]/ { /^[^[]/ p;}' yourinputfile
# cat tst
hfshfjk
[GENERAL]
DESC = "channel synchro TGG01"
DMM_VER = DMM23
PATH_FIFO = /users/tgg00/fifo
[EMITTER]
lmkmlfds
# sed -n '/\[GENERAL]/,/\[EMITTER]/ { /^[^[]./ p;}' tst
DESC = "channel synchro TGG01"
DMM_VER = DMM23
PATH_FIFO = /users/tgg00/fifo
#