Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding nested delimiters
#1
Greetings all,
I have a configuration file and after much reviewing I found there is some structure to it, but not sure how to reach in and get the elements out of it. So the file can be quite large, but I am trying to parse through some Firewall configurations and what I found is that for every line that starts with 'config' there is a corresponding line that starts with 'end' which make up the block of code. But inside each of these there could be many other config end pairs. For Clarity I indented the text below, but all of these are at the beginning of the line so ^config and ^end. There are other config and end pairs in the code, but they are tab indented so they will not matter.
Is there a module or something that would match brackets or something? Then I could start the script and change every line that startswith 'config' to {config and evey line that startswith 'end' to end} and then be able to parse through it. So at the end of the day:
would be a set of text I would work with etc....

config system global
information
end

config global
    config system global
        information
    end
    config system accprofile
        information
    end
    config system np6
        information
    end
    config system interface
         information   
    end
    config system custom-language
        information    
    end
    config system admin
        information    
    end
end  <<<<< ends the config global from above
config vdom
    config system settings
        information    
    end
    config system replacemsg-group
        information
    end
    config firewall address
        information
    end
    config firewall multicast-address
        information
    end
end <<< ends the config vdom from above
config vdom
    config system settings
        information
    end
    config system replacemsg-group
        information
    end
    config firewall address
        information
    end
    config firewall multicast-address
        information
    end
end  <<< ends the config vdom from above
Reply


Messages In This Thread
Finding nested delimiters - by wfsteadman - Jan-21-2018, 07:24 PM
RE: Finding nested delimiters - by Gribouillis - Jan-21-2018, 08:52 PM
RE: Finding nested delimiters - by wfsteadman - Jan-22-2018, 04:01 AM
RE: Finding nested delimiters - by Gribouillis - Jan-22-2018, 06:24 AM
RE: Finding nested delimiters - by DeaD_EyE - Jan-22-2018, 07:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delimiters - How to skip some html tags from being translate Melcu54 0 1,619 May-26-2021, 06:21 AM
Last Post: Melcu54
  Parse String between 2 Delimiters and add as single list items lastyle 5 3,282 Apr-11-2021, 11:03 PM
Last Post: lastyle
  Split string between two different delimiters, with exceptions DreamingInsanity 2 1,977 Aug-24-2020, 08:23 AM
Last Post: DreamingInsanity
  Finding value in nested dictionaries with lists mart79 16 7,738 Mar-08-2020, 08:16 PM
Last Post: ndc85430
  Problem with delimiters johnprada 5 2,641 Jan-29-2020, 10:17 AM
Last Post: DeaD_EyE
  Problem with delimiters johnprada 1 1,923 Jan-28-2020, 04:27 PM
Last Post: buran
  splitting a string with 2 different delimiters Skaperen 4 2,646 Dec-30-2019, 04:49 AM
Last Post: BamBi25
  Split a long string into other strings with no delimiters/characters krewlaz 4 2,702 Nov-15-2019, 02:48 PM
Last Post: ichabod801
  re.split multiple delimiters problem gw1500se 2 3,563 Jun-24-2019, 02:43 PM
Last Post: gw1500se

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020