Python Forum
re.finditer issue, output is blank
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
Reply
#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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why the blank lines in output? Mark17 6 1,388 Jun-27-2022, 11:21 PM
Last Post: Mark17
  blank graph with matplotlib from a csv file / data type issue arsentievalex 0 1,912 Apr-06-2021, 10:08 AM
Last Post: arsentievalex
  CSV gives me blank row on PC, but not a Mac bazcurtis 2 2,740 Jan-06-2020, 08:40 AM
Last Post: buran
  multithreading issue with output mr_byte31 4 3,148 Sep-11-2019, 12:04 PM
Last Post: stullis
  Output issue twinpiques 6 3,094 Jul-29-2019, 11:24 PM
Last Post: Yoriz
  25 blank lines in my sorted_fruits output list! raven61 7 4,210 Aug-09-2018, 11:30 PM
Last Post: raven61
  Paramiko output printing issue anna 3 15,951 Feb-06-2018, 08:34 AM
Last Post: anna
  Encoding issue for the console output ted_chou12 4 3,397 Sep-08-2017, 09:11 AM
Last Post: ted_chou12
  Using mmap.mmap and re.finditer Larz60+ 3 4,157 Apr-26-2017, 02:57 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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