Reputation: 77
I've got a script that searches through a logfile for a specific trigger, and then pulls out the line when it's found. For example, this is a line I'm looking for:
7/2/10 9:24:12 AM puppetmasterd[63092] Could not resolve 10.13.1.190: no name for 10.13.1.190
It saves this line into a variable "line", but I'd like to be able to extract only the IP Address.
Our IP Addresses all start with 10.13 - is there an easy way to search for that in this variable and then isolate ONLY the IP address into a variable?
Upvotes: 2
Views: 1115
Reputation: 92792
matches = line.scan(/10\.13\.[12]?[0-9]?[0-9]\.[12]?[0-9]?[0-9]/);
Upvotes: 2
Reputation: 13429
You want to read about regular expressions on Ruby. Your specific problem is fairly easy, so it would be a good learning exercise. (Try the tutorial if the first link is too advanced!)
Upvotes: 0