Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 re.finditer issue, output is blank
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 =
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",
for intf_ip in interface_ips:
    print("%s %s/%s %s" % ("intf_name"),
below is my input file.

interface Eth-Trunk1.120
vlan-type dot1q 120
ip address
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
ip address
traffic-policy INFRA-ACL inbound
user-queue cir 10240 pir 10400 inbound
user-queue cir 10240 pir 10400 outbound
statistic enable
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.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  CSV gives me blank row on PC, but not a Mac bazcurtis 2 340 Jan-06-2020, 08:40 AM
Last Post: buran
  multithreading issue with output mr_byte31 4 507 Sep-11-2019, 12:04 PM
Last Post: stullis
  Output issue twinpiques 6 631 Jul-29-2019, 11:24 PM
Last Post: Yoriz
  blank space + input() ClassicalSoul 6 800 Mar-06-2019, 09:50 AM
Last Post: perfringo
  25 blank lines in my sorted_fruits output list! raven61 7 1,337 Aug-09-2018, 11:30 PM
Last Post: raven61
  Paramiko output printing issue anna 3 8,460 Feb-06-2018, 08:34 AM
Last Post: anna
  Pygsheets Keeps inserting a blank row, Need Help HiImNew 1 1,184 Jan-26-2018, 08:48 AM
Last Post: buran
  Encoding issue for the console output ted_chou12 4 1,479 Sep-08-2017, 09:11 AM
Last Post: ted_chou12

Forum Jump:

Users browsing this thread: 1 Guest(s)