Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 re.finditer issue, output is blank
#1
Hi All,

trying below code, running with out error, however output is blank.


import re
from ciscoconfparse import CiscoConfParse
from ciscoconfparse.ccp_util import IPv4Obj

with open("conf.txt") as file:
   data = file.read()
interface_ips = re.finditer(r"^(interface (?P<intf_name>.*)\n)"
                            r"( .*\n)*"
                            r"( ip address (?P<ipv4_address>\S+) (?P<subnet_mask>\S+))\n"
                            r"( description (?P<description>.*))\n",
                                data,re.MULTILINE)
for intf_ip in interface_ips:
    print("%s %s/%s %s" % (intf_ip.group("intf_name"),
                           intf_ip.group("ipv4_address"),
                           intf_ip.group("subnet_mask"),
                           intf_ip.group("description")))
below is my input file.


interface Eth-Trunk1.120
vlan-type dot1q 120
description EXT_COGENT E SERVICES PRIVATE LIMITED_12005744750_50MB
ip address 111.93.43.217 255.255.255.252
traffic-policy INFRA-ACL inbound
qos-profile 50Mbps inbound identifier none
qos-profile 50Mbps outbound identifier none
statistic enable
#
interface Eth-Trunk1.123
vlan-type dot1q 123
description EXT_ILL_SARALA-HANDICRAFTS_PANIPAT_5018027739
ip address 182.156.211.161 255.255.255.252
traffic-policy INFRA-ACL inbound
user-queue cir 10240 pir 10400 inbound
user-queue cir 10240 pir 10400 outbound
statistic enable
Quote
#2
In your regex, ip address comes before description, in the input file, it's the opposite.
Also, if this is a common file format, you might want to try looking up an existing parser instead of doing your own regex-based parsing.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  XlsxWriter: How can I append new data into not blank cells? aquerci 1 167 Jun-01-2019, 04:37 AM
Last Post: heiner55
  I want to validate that there is not more than two blank spaces in a string of charac jlpavon1987 4 238 Mar-29-2019, 10:49 PM
Last Post: woooee
  Running script pops up python.exe but blank Beerendar 9 468 Mar-28-2019, 07:38 PM
Last Post: nilamo
  blank space + input() ClassicalSoul 6 333 Mar-06-2019, 09:50 AM
Last Post: perfringo
  Unexpected output when searching for a string from os.popen output FujiJean 3 543 Oct-02-2018, 11:39 AM
Last Post: volcano63
  25 blank lines in my sorted_fruits output list! raven61 7 763 Aug-09-2018, 11:30 PM
Last Post: raven61
  Paramiko output printing issue anna 3 4,540 Feb-06-2018, 08:34 AM
Last Post: anna
  Pygsheets Keeps inserting a blank row, Need Help HiImNew 1 832 Jan-26-2018, 08:48 AM
Last Post: buran
  Encoding issue for the console output ted_chou12 4 1,060 Sep-08-2017, 09:11 AM
Last Post: ted_chou12
  Using mmap.mmap and re.finditer Larz60+ 3 1,246 Apr-26-2017, 02:57 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)