A Note on TextFSM

TextFSM is a module written to simply the process of extracting information out of semi-structured outputs (such as CLI command output) that are meant for human readability. TextFSM uses a template file to define what values we are looking for, as well as how those values get extracted from the output. You can read some examples of using the TextFSM Wiki and the Code Lab section for additional examples.

In addition, there is a large repository of TextFSM templates located in Network To Code’s Github Repository. This repository contains TextFSM templates for a variety of vendors and to process a large number of commands. At best, they’ll have the template you need that is already created, but in some cases you may need to modify the template to get what you want from it.

In the end, TextFSM still boils down to text matching with Regular Expressions (RegEx), although TextFSM puts some structure around it that makes it much easier than trying to write matching by-hand – especially for more complicated outputs like a routing table. If you are unfamiliar with RegEx, I’m sure there are plenty of primers on how they work online. I would highly recommend that if you are trying to develop some new regular expressions or a TextFSM template that you use a site such as regex101.com to see real-time feedback of what your expressions will match against some sample data you’ve pasted into the site.