Coder Social home page Coder Social logo

Comments (4)

byadair avatar byadair commented on June 8, 2024

import textfsm
import tempfile
a="""AP1 GigabitEthernet0 UP 1000
GigabitEthernet1 DOWN AUTO
AP2 GigabitEthernet0 UP 1000
AP3 GigabitEthernet0 UP 1000"""

t="""Value Filldown AP_NAME (\S+)
Value Filldown PORT (\S+)
Value Filldown STATUS (\S+)
Value Filldown SPEED (\S+)

Start
^${AP_NAME}?\s+${PORT}\s+${STATUS}\s+${SPEED}\s*$$ -> Record
"""

tf=tempfile.TemporaryFile("r+")
tf.write(t)
tf.seek(0)
tx=textfsm.TextFSM(tf)
result=tx.ParseText(a)
print(result)

from textfsm.

marceardz avatar marceardz commented on June 8, 2024

Thanks @byadair this was super helpful!!! Do you know if there is a way of filling the Name column for the ones that have multiline? As with the proposed solution the multilines are now being included, which is great!! But the Name attribute is not getting repeated and is showing up as blank. Like this:
AP1 GigabitEthernet0 UP 1000
GigabitEthernet1 DOWN AUTO
AP2 GigabitEthernet0 UP 1000
AP3 GigabitEthernet0 UP 1000

from textfsm.

byadair avatar byadair commented on June 8, 2024

Sorry for wrong scripts.

import textfsm
import tempfile
a="""AP1 GigabitEthernet0 UP 1000
GigabitEthernet1 DOWN AUTO
AP2 GigabitEthernet0 UP 1000
AP3 GigabitEthernet0 UP 1000
"""

t="""Value Filldown AP_NAME (\S+)
Value PORT (\S+)
Value STATUS (\S+)
Value SPEED (\S+)

Start
^${AP_NAME}\s+${PORT}\s+${STATUS}\s+${SPEED}\s* -> Record
^${PORT}\s+${STATUS}\s+${SPEED}\s* -> Record

EOF"""

tf=tempfile.TemporaryFile("r+")
tf.write(t)
tf.seek(0)
tx=textfsm.TextFSM(tf)
result=tx.ParseText(a)
for line in result:
print(line)

#['AP1', 'GigabitEthernet0', 'UP', '1000']
#['AP1', 'GigabitEthernet1', 'DOWN', 'AUTO']
#['AP2', 'GigabitEthernet0', 'UP', '1000']
#['AP3', 'GigabitEthernet0', 'UP', '1000']

from textfsm.

marceardz avatar marceardz commented on June 8, 2024

Thanks @byadair, I was about to update the thread saying that adding an extra record will fix the issue!! Thanks for all the learnings!! I added a "Required" as well in one of the attributes to remove the extra filldown from the last row.

from textfsm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.