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
  multithreading issue with output mr_byte31 4 199 Sep-11-2019, 12:04 PM
Last Post: stullis
  Output issue twinpiques 6 227 Jul-29-2019, 11:24 PM
Last Post: Yoriz
  blank space + input() ClassicalSoul 6 466 Mar-06-2019, 09:50 AM
Last Post: perfringo
  25 blank lines in my sorted_fruits output list! raven61 7 899 Aug-09-2018, 11:30 PM
Last Post: raven61
  Paramiko output printing issue anna 3 5,987 Feb-06-2018, 08:34 AM
Last Post: anna
  Pygsheets Keeps inserting a blank row, Need Help HiImNew 1 926 Jan-26-2018, 08:48 AM
Last Post: buran
  Encoding issue for the console output ted_chou12 4 1,194 Sep-08-2017, 09:11 AM
Last Post: ted_chou12

Forum Jump:


Users browsing this thread: 1 Guest(s)