google / textfsm

Python module for parsing semi-structured text into python tables.
Apache License 2.0
1.11k stars 171 forks source link

Textfsm column is getting populated more than required #117

Closed Bakahuman closed 8 months ago

Bakahuman commented 1 year ago

I have an input textfile that looks like this

Field1A
  Field2 : A1
    Field3 : A1.5
      Field4: 1
      Field4: 2
  Field2 : A2
    Field4: 3     

Field1B
  Field2 : B1
    Field3 : B1.5
      Field4: 4   
      Field4: 5

Field1C
  Field2 : C 
    Field4: 6

and a textfsm template that looks like this

Value Filldown FIELD1 (\S+)
Value Filldown FIELD2 (\S+)
Value Filldown FIELD3 (\S+)
Value Required FIELD4 (\S+)

Start
  ^\s*${FIELD1}\s*$$
  ^\s*Field2\s*:\s*${FIELD2}\s*
  ^\s*Field3\s*:\s*${FIELD3}\s*
  ^\s*Field4:\s*${FIELD4}\s* -> Record

This should give me an output where the Field3 is only getting populated for the field4 rows that it is applicable for but it is populating for even the field4 rows that it's not a part of.

The ideal output should look like this

FIELD1    FIELD2    FIELD3      FIELD4
--------  --------  --------  --------
Field1-A  A1        A1.5           1
Field1-A  A1        A1.5           2
Field1-A  A2                       3
Field1-B  B1        B1.5           4
Field1-B  B1        B1.5           5
Field1-C  C                        6

but I'm getting this output below

FIELD1    FIELD2    FIELD3      FIELD4
--------  --------  --------  --------
Field1-A  A1        A1.5           1
Field1-A  A1        A1.5           2
Field1-A  A2        A1.5           3
Field1-B  B1        B1.5           4
Field1-B  B1        B1.5           5
Field1-C  C         B1.5           6

what is the ideal fix for this issue ?

harro commented 8 months ago

This is working as intended - as you are using 'Filldown'.

Note: When a Record happens only non Filldown values are cleared.

Remove Filldown from all your values - this will give you what you want.