EVE-NG Linux VM SSH troubleshooting
September 20, 2025
Parsing text with TextFSM
TextFSM is a framework developed by Google that enables the transformation (parsing) of human-readable text into structured, machine-readabl
TextFSM is a framework developed by Google that enables the transformation (parsing) of human-readable text into structured, machine-readable output.
TextFSM, available as a Python module, is one of the essential tools when automating a network device that requires CLI interaction, allowing us to interpret the output in order to make decisions.
Let’s look at an example: we want to analyze the interfaces of a switch and shut down the ones that are not connected.
The following output is human-readable, but it cannot be used directly within a script.
TextFSM helps convert the above output into a structured format:
Finite State Machine
TextFSM operates as a finite state machine (FSM), starting from the Start state and implicitly ending at the EOF state, which is reached at the end of the file.
The process can be summarized as follows:
- The first line of the input text is read
- The line is matched against a set of rules, starting from the top
- If a rule matches, the corresponding action is executed and the line is “consumed”
- The next line of the input is read and matched against the rule set again, starting from the top
- Once the entire input has been processed, the FSM terminates and returns the structured output
The actions, described below, can modify the default behavior of the FSM.
Rule Actions
A simple template contains a set of rules within the Start state, which is mandatory. The Start state is the entry point of the FSM and processes the rules defined within it, starting from the first.
Each rule consists of a regular expression followed by one or more optional actions. Actions can be categorized as follows:
- Line Action: allows control over the selection of the next input line and, consequently, which rule will be applied next.
- Record Action: allows control over how the extracted values are stored in a record.
- State Transition: allows moving to a different state.
Consider the following example :
Continue reading the post on Patreon .