Trouble with sed and ini file parsing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble with sed and ini file parsing
# 1  
Old 01-10-2012
Trouble with sed and ini file parsing

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 :

Code:
; 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 ...

Code:
sed -ne '/\[GENERAL\]/,/\[EMITTER\]/ p' < $my_ini_file


with this method the output is :

Code:
[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 !
# 2  
Old 01-10-2012
Hi odium74,

One way:
Code:
$ sed -ne '/\[GENERAL\]/,/\[EMITTER\]/ { /^\(\[\|\s*$\)/ b ; p }' infile
DESC = "channel synchro TGG01"
DMM_VER = DMM23
PATH_FIFO = /users/tgg00/fifo

Regards,
Birei
# 3  
Old 01-10-2012
Another one with awk:
Code:
# awk '/^\[GENERAL/ {x=1; next} /^\[/ {x=0} x==1 && !/^[\t ]*$/' infile
DESC = "channel synchro TGG01"
DMM_VER = DMM23
PATH_FIFO = /users/tgg00/fifo

# 4  
Old 01-10-2012
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 ..

Code:
sed -ne '/\[GENERAL\]/,/\[EMISSION\]/ { /^\(\[\|\s*$\)/ b ; p }' < $my_ini_file

output error :

Code:
sed: There are too many '{'.

any alternative ?

thank you
# 5  
Old 01-10-2012
Sorry, I can't help much with that. It works in my system:
Code:
$ 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.
Code:
$ sed -ne '/\[GENERAL\]/,/\[EMITTER\]/ { /^\(\[\|[ ]*$\)/ b ; p; };' infile

Regards,
Birei.
# 6  
Old 01-10-2012
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 Smilie

Code:
sed -n '/\[GENERAL]/,/\[EMITTER]/ { /^[^[]/ p;}' yourinputfile

Code:
# cat tst
hfshfjk
[GENERAL]

DESC = "channel synchro TGG01"
DMM_VER = DMM23
PATH_FIFO = /users/tgg00/fifo

[EMITTER]
lmkmlfds

Code:
# sed -n '/\[GENERAL]/,/\[EMITTER]/ { /^[^[]./ p;}' tst
DESC = "channel synchro TGG01"
DMM_VER = DMM23
PATH_FIFO = /users/tgg00/fifo
#


Last edited by ctsgnb; 01-10-2012 at 02:16 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a fixed column text file in sed

I have a text file with records of the form: A X1 Y1 X2 Y2 X3 Y3 where A is character length 10, Xi is character length 4 and Yi is numeric length 10. I want to parse the line, and output records like: A X1 Y1 A X2 Y2 A X3 Y3 etc Can anyone please give me an idea of how to do this. ... (4 Replies)
Discussion started by: wvdeijk
4 Replies

2. Shell Programming and Scripting

sed - String substitution within specified section in ini type file

Hello. I am trying to modify a config file which is in windows *.ini type file. I have found a piece of code here :linux - Edit file in unix using SED - Stack Overflow As I can't make it doing the job , I am trying to find a solution step by step. here a modified sample file : my_sample.ini... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

Parsing file: struggling against sed command

Hello fellows, Sure you can help this poor guy that is struggling against sed command, being unable to tame it I have a lot of files like this: From this one, I need to obtain values highlighted in bold/red To do so, I am executing this piece of code inside a loop: ... (10 Replies)
Discussion started by: manolain
10 Replies

4. Shell Programming and Scripting

Help in parsing xml file (sed/nawk)

I have a large xml file as shown below: <input> <blah> <blah> <atr="blah blah value = ""> <blah> <blah> </input> ..2nd chunk... ..3rd chunk... ...4th chunk... All lines between <input> and </input> is one 'order' and this 'order' is repeated... (14 Replies)
Discussion started by: shekhar2010us
14 Replies

5. UNIX for Advanced & Expert Users

Parsing through a file with awk/sed

I don't necessary have a problem, as I have a solution. It is just that there may be a better solution. GOAL: Part one: Parse data from a file using the "\" as a delimiter and extracting only the last delimiter. Part two: Parse same file and extract everything but the last delimited item. ... (8 Replies)
Discussion started by: OrangeYaGlad
8 Replies

6. Shell Programming and Scripting

Parsing complicated CSV file with sed

Yes, there is a great doc out there that discusses parsing csv files with sed, and this topic has been covered before but not enough to answer my question (unix.com forums). I'm trying to parse a CSV file that has optional quotes like the following: "Apple","Apples, are fun",3.60,4.4,"I... (3 Replies)
Discussion started by: analog999
3 Replies

7. Shell Programming and Scripting

SED 4.1.4 - INI File Change Problem in Variables= in Specific [Sections] (Guru Help)

GNU sed version 4.1.4 on Windows XP SP3 from GnuWin32 I think that I've come across a seemingly simple text file change problem on a INI formatted file that I can't do with SED without side effects edge cases biting me. I've tried to think of various ways of doing this elegantly and quickly... (5 Replies)
Discussion started by: JakFrost
5 Replies

8. Shell Programming and Scripting

awk/sed for parsing file

Hi All, I have a log file like this E Mon Oct 06 00:17:08 2008 xxx2 cm:10614 fm_pi2_svc_iptv_purchase.c:149 1:pin_deferred_act:10601:11:169:1223245028:16 pi2_op_svc_iptv_purchase error <location=PIN_ERRLOC_FM:5 class=PIN_ERRCLASS_SYSTEM_DETERMINATE:1... (10 Replies)
Discussion started by: subin_bala
10 Replies

9. Shell Programming and Scripting

Parsing a file (sed/awk?)

Hello people, newbie question. I'm trying to parse these type of file 1 "CAR " " C1 " " " 6 0 C1 2 "CAR " " O1A" " " 8 0 O1A 3 "CAR " " O1B" " " 8 -1 O1B 4 "CAR " " C2 " " " 6 0 C2 5 "CAR " " C3 " " " 6 ... (10 Replies)
Discussion started by: aristegui
10 Replies

10. UNIX for Advanced & Expert Users

Parsing xml file using Sed

Hi All, I have this(.xml) file as: <!-- define your instance here --> <instance name='ins_C2Londondev' user='' group='' fullname='B2%20-%20London%20(dev)' > <property> </property> </instance> I want output as: <!-- define your instance here --> <instance... (3 Replies)
Discussion started by: kapilkinha
3 Replies
Login or Register to Ask a Question

Featured Tech Videos