I am looking for a single regexp that will match either of these 2 lines, and capture/group the values for speed and duplex.
speed: 1000Mbps (Duplex: full)
speed: n/a
Line #1 should have group 1 with value '1000Mbps' and group 2 value 'full'. Line #2 would have group 1 only, with value 'n/a'
This is closest I could get, trying to use an alternate inside a nested group. It gets me speed values, for not duplex values.
^\s+speed:\s+(\S+)\s*(|\(Duplex:\s+(\S+)\))
Longer Version
This is for a TextFSM template. I will include those details here, in case using FSM there is an easy way to accomplish the above.
Sample data:
== [onboard]
==[mgmt]
mode: static
ip: 1.2.3.4 255.255.255.248
ipv6: ::/0
status: up
speed: 1000Mbps (Duplex: full)
==[port1]
mode: static
ip: 0.0.0.0 0.0.0.0
ipv6: ::/0
status: down
speed: n/a
Here is the template file I am using:
Value Required NAME (\S+)
Value MODE (\S+)
Value IP (\d+?\.\d+?\.\d+?\.\d+?)
Value NETMASK (\S+)
Value STATUS (\S+)
Value SPEED (\S+)
Value DUPLEX (\S+)
Start
^==\s+\[onboard\]
^\s+==\[${NAME}\]
^\s+mode:\s+${MODE}
^\s+ip:\s+${IP}\s+${NETMASK}
^\s+ipv6:\s+.*
^\s+status:\s+${STATUS}
^\s+speed:\s+${SPEED}\s+\(Duplex:\s+${DUPLEX}\) -> Record
^\s*$$
^. -> Error
I've made several attempts to the above, including a 2nd line to match 'speed' that doesn't have 'Duplex' on it. Tried having both lines Record action, or just one, or the last catch-all. Is there someway to specify an OR type of statement in FSM? Attempt to match input line against this, if no match, try against that?
Edit: thanks for the replies. I am not able to get any of those examples working in TextFSM however.