ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Solved Need to parse large conf files

    IT Discussion
    scripting asterisk config
    6
    53
    2.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • JaredBuschJ
      JaredBusch @matteo nunziati
      last edited by JaredBusch

      @matteo-nunziati said in Need to parse large conf files:

      quite late here... sorry I've just an half backed solution:

       grep -e "^exten\|^[\|^;;" filename
      

      That is the ballpark, but many lines are comments that are not needed.

      I was simply going to loop down the file each time through the loop putting the previosu line back one vairable. that part was simple.

      The catching the exten => STUFF,1 is the harder part. it HAS to be that full syntaxt.

      matteo nunziatiM 1 Reply Last reply Reply Quote 0
      • 1
        1337 @JaredBusch
        last edited by 1337

        @JaredBusch

        Jared, will this do as a test file?

        ;; This is a test file
        [context_1]
        
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;   Ben's inbound 2344242342                      ;
        ;    This extension is not suppose to go through   ;
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => 2344242342,2,NoOp()
        same => n,Goto(main,123456,1)
        same => n,Hangup()
        
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;   Bob's inbound 3145551212                      ;
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => 3145551212,1,NoOp()
        same => n,Goto(main,123456,1)
        same => n,Hangup()
        
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;  Mary's inbound 4534535345                      ;
        ;   With some added comments                       ;
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => 4534535345,1,NoOp()
        same => n,Goto(main,123456,1)
        same => n,Hangup()
        
        [context_2]
        exten => 33333333,1,NoOp()
        same => n,Goto(main,123456,1)
        same => n,Hangup()
        
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;   What is this????????????                      ;
        ;    Lets add a long comment section               ;
        ;    Line 3,,,                                     ;
        ;    Line 4;Let's see if that comment remains      ;
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => 3145454,1,NoOp()
        same => n,Goto(main,123456,1)
        same => n,Hangup()
        
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;;  Let's make a wonky comment line here
        
        ;   And lets add this too                         ;;
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        exten => 232342,1,NoOp()
        same => n,Hangup()
        
        [context_3]
        exten => 7777777,1
        exten => 8888888,1,NoOp()
        ;; Let's do these without comments
        
        JaredBuschJ 1 Reply Last reply Reply Quote 0
        • JaredBuschJ
          JaredBusch @1337
          last edited by

          @Pete-S said in Need to parse large conf files:

          @JaredBusch

          Jared, will this do as a test file?

          Close enough. I just moved your original sample code to the server as a starting point. (no PHP installed on my laptop to test locally).

          1 1 Reply Last reply Reply Quote 0
          • 1
            1337 @JaredBusch
            last edited by 1337

            @JaredBusch said in Need to parse large conf files:

            @Pete-S said in Need to parse large conf files:

            @JaredBusch

            Jared, will this do as a test file?

            Close enough. I just moved your original sample code to the server as a starting point. (no PHP installed on my laptop to test locally).

            Let me just make some changes and test it on the test file. And I'll post it again.

            PS. And what do you want the output to look like?

            1 Reply Last reply Reply Quote 0
            • matteo nunziatiM
              matteo nunziati @JaredBusch
              last edited by matteo nunziati

              @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

              try:

              ^exten => .*,1,.*$
              
              JaredBuschJ 1 Reply Last reply Reply Quote 0
              • JaredBuschJ
                JaredBusch @1337
                last edited by

                @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.

                1 1 Reply Last reply Reply Quote 0
                • JaredBuschJ
                  JaredBusch @matteo nunziati
                  last edited by

                  @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.

                  1 matteo nunziatiM 2 Replies Last reply Reply Quote 0
                  • 1
                    1337 @JaredBusch
                    last edited by

                    @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?

                    JaredBuschJ 1 Reply Last reply Reply Quote 0
                    • JaredBuschJ
                      JaredBusch @1337
                      last edited by

                      @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.

                      1 Reply Last reply Reply Quote 0
                      • 1
                        1337 @JaredBusch
                        last edited by

                        @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 ??

                        JaredBuschJ 1 Reply Last reply Reply Quote 0
                        • JaredBuschJ
                          JaredBusch @1337
                          last edited by

                          @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.

                          1 2 Replies Last reply Reply Quote 0
                          • matteo nunziatiM
                            matteo nunziati @JaredBusch
                            last edited by

                            @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.

                            1 Reply Last reply Reply Quote 1
                            • 1
                              1337 @JaredBusch
                              last edited by

                              @JaredBusch Could you check that you can run command line php on the server?
                              Just execute php -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.

                              JaredBuschJ 1 Reply Last reply Reply Quote 0
                              • 1
                                1337 @JaredBusch
                                last edited by 1337

                                @JaredBusch
                                Also is it just one conf file you need to search through or many in the same directory ?

                                JaredBuschJ 1 Reply Last reply Reply Quote 0
                                • JaredBuschJ
                                  JaredBusch @1337
                                  last edited by

                                  @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 execute php -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.

                                  1 Reply Last reply Reply Quote 0
                                  • JaredBuschJ
                                    JaredBusch @1337
                                    last edited by

                                    @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.

                                    1 1 Reply Last reply Reply Quote 0
                                    • 1
                                      1337 @JaredBusch
                                      last edited by 1337

                                      @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?

                                      JaredBuschJ 1 Reply Last reply Reply Quote 0
                                      • JaredBuschJ
                                        JaredBusch @1337
                                        last edited by

                                        @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.

                                        1 Reply Last reply Reply Quote 0
                                        • matteo nunziatiM
                                          matteo nunziati
                                          last edited by matteo nunziati

                                          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

                                          JaredBuschJ matteo nunziatiM 2 Replies Last reply Reply Quote 0
                                          • JaredBuschJ
                                            JaredBusch @matteo nunziati
                                            last edited by

                                            @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.

                                            1 Reply Last reply Reply Quote 1
                                            • 1
                                            • 2
                                            • 3
                                            • 2 / 3
                                            • First post
                                              Last post