Solved Need to parse large conf files
-
@Pete-S said in Need to parse large conf files:
And what should the end result look like?
more or less this
[context 1] ; comment line -3 if it exists ; comment line -2 if it exists ; comment line -1 if it exists exten => STUFF,1,STUFF
repeat for dial plans and context appropriately.
-
@matteo-nunziati said in Need to parse large conf files:
@JaredBusch said in Need to parse large conf files:
The catching the exten => STUFF,1 is the harder part. it HAS to be that full syntaxt.
no it is simple with regex IF the line is:
exten => bla,1,bla
100% those are the only exten lines I want.
-
@JaredBusch said in Need to parse large conf files:
@Pete-S said in Need to parse large conf files:
And what should the end result look like?
more or less this
[context 1] ; comment line -3 if it exists ; comment line -2 if it exists ; comment line -1 if it exists exten => STUFF,1,STUFF
repeat for dial plans and context appropriately.
All the comment lines or just the last/first three?
-
@Pete-S said in Need to parse large conf files:
@JaredBusch said in Need to parse large conf files:
@Pete-S said in Need to parse large conf files:
And what should the end result look like?
more or less this
[context 1] ; comment line -3 if it exists ; comment line -2 if it exists ; comment line -1 if it exists exten => STUFF,1,STUFF
repeat for dial plans and context appropriately.
All the comment lines or just the last/first three?
i was just going with the up to three lines after the first visual scan of the files.
-
@JaredBusch said in Need to parse large conf files:
@matteo-nunziati said in Need to parse large conf files:
@JaredBusch said in Need to parse large conf files:
The catching the exten => STUFF,1 is the harder part. it HAS to be that full syntaxt.
no it is simple with regex IF the line is:
exten => bla,1,bla
100% those are the only exten lines I want.
Is it possible to have
exten => bla,2,bla
?? -
@Pete-S said in Need to parse large conf files:
@JaredBusch said in Need to parse large conf files:
@matteo-nunziati said in Need to parse large conf files:
@JaredBusch said in Need to parse large conf files:
The catching the exten => STUFF,1 is the harder part. it HAS to be that full syntaxt.
no it is simple with regex IF the line is:
exten => bla,1,bla
100% those are the only exten lines I want.
Is it possible to have
exten => bla,2,bla
??Yes, but I do not want them.
-
@JaredBusch said in Need to parse large conf files:
@matteo-nunziati said in Need to parse large conf files:
@JaredBusch said in Need to parse large conf files:
The catching the exten => STUFF,1 is the harder part. it HAS to be that full syntaxt.
no it is simple with regex IF the line is:
exten => bla,1,bla
100% those are the only exten lines I want.
@Pete-S if the php code works for @JaredBusch , just substitute the search part with the provided regex.
-
@JaredBusch Could you check that you can run command line php on the server?
Just executephp -v
and you'll get the version.At least on debian you need to have php-cli package and I don't know if you do.
-
@JaredBusch
Also is it just one conf file you need to search through or many in the same directory ? -
@Pete-S said in Need to parse large conf files:
@JaredBusch Could you check that you can run command line php on the server?
Just executephp -v
and you'll get the version.At least on debian you need to have php-cli package and I don't know if you do.
I can.
-
@Pete-S said in Need to parse large conf files:
@JaredBusch
Also is it just one conf file you need to search through or many in the same directory ?many. but feeding that into a loop is simple once I work this out.
-
@JaredBusch said in Need to parse large conf files:
@Pete-S said in Need to parse large conf files:
@JaredBusch
Also is it just one conf file you need to search through or many in the same directory ?many. but feeding that into a loop is simple once I work this out.
I had file scanning already in the example file but can take it out. The reason I'm asking is if you need to have the filename too in the "report" for each extension?
-
@Pete-S said in Need to parse large conf files:
@JaredBusch said in Need to parse large conf files:
@Pete-S said in Need to parse large conf files:
@JaredBusch
Also is it just one conf file you need to search through or many in the same directory ?many. but feeding that into a loop is simple once I work this out.
I had file scanning already in the example file but can take it out. The reason I'm asking is if you need to have the filename too in the "report" for each extension?
Yes. but why i dunno. this is all a hand coded mess when compared to standards.
It is all perfectly valid syntax. and there are comments all over. but jsut wow.
-
ok my last s**t, just in case @JaredBusch doesn't know what to do waiting for @Pete-S
grep -B3 -n -e "^exten\|^[" $YOURFILENAME | sort -n | uniq | cut -f2 -d: | cut -f2 -d- | grep -e "^[e[\;]"
still not granted to get only valid exten
-
@matteo-nunziati said in Need to parse large conf files:
ok my last s**t, just in case @JaredBusch doesn't know what to do waiting for @Pete-S
I'm not waiting. I'm doing my thing too.
-
@matteo-nunziati said in Need to parse large conf files:
ok my last s**t, just in case @JaredBusch doesn't know what to do waiting for @Pete-S
grep -B3 -n -e "^exten\|^[" $YOURFILENAME | sort -n | uniq | cut -f2 -d: | cut -f2 -d- | grep -e "^[e[\;]"
still not granted to get only valid exten
this is the outcome for @Pete-S test file:
;; This is a test file [context_1] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Ben's inbound 2344242342 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; exten => 2344242342,1,NoOp() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Bob's inbound 3145551212 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; exten => 3145551212,1,NoOp() ;; Mary's inbound 4534535345 ; ; With some added comments ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; exten => 4534535345,1,NoOp() [context_2] exten => 33333333,1,NoOp() ; Line 3,,, ; ; Line 4;Let's see if that comment remains ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; exten => 3145454,1,NoOp() ; And lets add this too ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; exten => 232342,1,NoOp() [context_3] exten => 7777777,1 exten => 8888888,1,NoOp()
-
@matteo-nunziati said in Need to parse large conf files:
ok my last s**t, just in case @JaredBusch doesn't know what to do waiting for @Pete-S
still not granted to get only valid extendoens't work right on a live file. close. but not correct.
-
@JaredBusch said in Need to parse large conf files:
// find matching files, put in array called filename
$filename:=glob("*.ini");it doesn't like the
:
I moved a copy of the files to the FreePBX 14 box since PHP 5.6 is "current" for CentOS.
[jbusch@cccfreepbx newton_conf]$ sudo -u asterisk php parseit.php PHP Parse error: syntax error, unexpected ':' in /var/www/html/newton_conf/parseit.php on line 3
-
Hang on a sec. I'm just about finished.
-
This is the output:
File: sample.conf [context_1] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Bob's inbound 3145551212 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; exten => 3145551212,1,NoOp() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Mary's inbound 4534535345 ; ; With some added comments ; exten => 4534535345,1,NoOp() [context_2] exten => 33333333,1,NoOp() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; What is this???????????? ; ; Lets add a long comment section ; exten => 3145454,1,NoOp() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Let's make a wonky comment line here ; And lets add this too ;; exten => 232342,1,NoOp() [context_3] exten => 7777777,1 exten => 8888888,1,NoOp()
Personally I'd format it a little for instance by remove all comment lines that are just ;;;;;; and all trailing and preceding ;
Or if it's just for viewing I'd html it.