0
I am searching in a series of large Redback config files for certain things, and I’m beginning to find Regex and Atom really powerful for this. The files are sometimes 20,000 lines long, and there are over 100 of them.
Of course I should script this, and someone more script savvy than me would do that in a trice, but I’ve come up with a part manual solution. Perhaps I will build it into a script later.
What I need to do is search each file for any ‘ip route’ commands that have a named interface as a next-hop rather than an IP address. So to do this, I am doing inverse-matching on four sets of numbers separated by dots.
I also need to exclude the keyword ‘context’ and the interface ‘null0’. This took me a while to figure out.
Here’s my pattern match:
ip route [0-9]+.[0-9]+.[0-9]+.[0-9]+/[0-9]+ (?![0-9]+.[0-9]+.[0-9]+.[0-9]+|context|null0)
This matches the string:
ip route 172.21.0.0/16 MADEUPINTERFACE
But not:
ip route 172.16.4.0/24 10.0.0.1
The expression is not very accurate, since it could match IP addresses like 999.999.999.999, but that does not matter in Continue reading