Comments (4)
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.
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.
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.
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)
- show cdp neighbor detail template fails when output includes VTP VTP Management Domain Name: null HOT 3
- download src via pip download requires six
- Only the last set of data can be matched HOT 2
- pypi - missing latest version HOT 1
- Bug with the brackets in the v1.1.2 version HOT 1
- Can't install textfsm 1.1.3 HOT 9
- Provide Wheel on pypi.org HOT 1
- Parsing Cisco NXOS-style configuration using textfsm HOT 2
- can line number record? HOT 3
- How to assign a default value HOT 1
- Retire copyable_regex_object.py HOT 1
- No need to have future as dependency HOT 4
- Textfsm column is getting populated more than required HOT 1
- Tarball on github reported as 1.1.3 is 1.1.2 HOT 1
- Remove v2 to v3 migration libraries HOT 4
- Question : Can we include textfsm template inside python code ? HOT 2
- Help with hardcore output HOT 2
- Please help to provide the syntax to parse the info using textfsm HOT 3
- Question: Is It Possible to Extract Data From Different Lines HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from textfsm.