Skip to content

Template syntax reference

Concise cheat sheet for TextFSM templates and CliTable index files, distilled from the Google TextFSM Wiki.

Template structure

Every template has two sections separated by one or more blank lines:

  1. Value definitions at the top (each line begins with Value).
  2. State definitions below (StateName header followed by indented rule lines).
Value [Option[,Option...]] Name (RegexPattern)

Start
  ^RulePattern -> [LineOp[.RecordOp]] [NextState]

Comment lines start with # and may appear between definitions. Inside rules, reference values as ${Name} (or $Name). Escape literal $ as $$ and literal # with \# if needed.

Value options

Combine multiple options with commas and no spaces (for example, Value Filldown,Required Vrf (\S+)):

Option Effect
Filldown Retain the last matched value across subsequent records
Fillup Fill empty values upward in previous rows until a match is found
Key Mark the field as part of the row's unique key (CliTable merges rows with matching keys)
Required Emit a record only when this value is non-empty at save time
List Append each match to a list instead of overwriting the current value

Rule actions

Actions follow -> and control line iteration, record emission, and state transitions:

Action Category Effect
Next Line (default) Stop checking rules for this line and read the next input line
Continue Line Keep the current input line and evaluate subsequent rules
Record Record Append current values as a row (if Required constraints pass) and reset non-Filldown values
NoRecord Record (default) Do not emit a row on this rule
Clear Record Reset non-Filldown values without recording
Clearall Record Reset all values, including Filldown memory
Error ["msg"] Line Raise TextFSMError immediately with optional message

Combine line and record actions with a dot (for example, Next.Record or Continue.Record). Note that Continue cannot be paired with a state transition.

Reserved states

State Meaning
Start Entry state (mandatory in every template)
EOF Optional state executed once at end of input (EOF suppresses the implicit final Record unless explicit)
End Terminal state that stops parsing immediately

CliTable index syntax

CliTable maps command attributes to templates using a comma-separated index file. See the CliTable wiki for full details:

  • The first line defines column headers.
  • The first column must be named Template and list .textfsm filenames (colon-separated if combining templates).
  • The last column matches the command string (typically Command) and supports bracket abbreviation syntax like sh[[ow]] ip bg[[p]].
  • Optional intermediate columns (such as Platform or Hostname) match Python regular expressions against lookup attributes.