简体   繁体   中英

TextFSM - how do I capture lines with blank fields

In the text below, I would like to extract the 3 services. However only the second 2 work, since teh Service Name in the first one is blank.

===============================================================================
ServiceId    Type      Adm  Opr  CustomerId Service Name
-------------------------------------------------------------------------------
100          VPRN      Up   Up   1          
2147483648   IES       Up   Down 1          _tmnx_InternalIesService
2147483649   intVpls   Up   Down 1          _tmnx_InternalVplsService
-------------------------------------------------------------------------------
Matching Services : 3
-------------------------------------------------------------------------------

Here is my template

Value Required SERVICE_ID (\S+)
Value Required TYPE (\S+)
Value Required ADMIN_STATE (Up|Down)
Value Required OPER_STATE (Up|Down)
Value Required CUSTOMER_ID (\d+)
Value Required SERVICE_NAME (\S+)

Start
 ^----------- -> Service

Service
  ^${SERVICE_ID}\s+${TYPE}\s+${ADMIN_STATE}\s+${OPER_STATE}\s+${CUSTOMER_ID}\s+(${SERVICE_NAME}\s*|\s+)$$ -> Record
  ^-+ -> Done
  ^=+
  ^Matching\s+Services
  ^\s*$$
  ^. -> Error

Done

The answer that was staring me in the face was the definition of the value which had 'Require'. Simply strip that and things work like a champ.

Value Required SERVICE_ID (\S+)
Value Required TYPE (\S+)
Value Required ADMIN_STATE (Up|Down)
Value Required OPER_STATE (Up|Down)
Value Required CUSTOMER_ID (\d+)
Value SERVICE_NAME (\S+)

Start
 ^----------- -> Service

Service
  ^${SERVICE_ID}\s+${TYPE}\s+${ADMIN_STATE}\s+${OPER_STATE}\s+${CUSTOMER_ID}\s+(${SERVICE_NAME}\s*|\s+)$$ -> Record
  ^-+ -> Done
  ^=+
  ^Matching\s+Services
  ^\s*$$
  ^. -> Error

Done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM