[vox-tech] bash scripting question
Micah Cowan
micah at cowan.name
Wed Apr 25 22:00:35 PDT 2007
Cylar Z wrote:
> Hey programming gurus...
>
> I want to write a script which takes a block of text
> and extracts any numbers which match a 123.456.789.012
> pattern. I am not looking for any numbers in
> particular (so I don't think the grep command will be
> of much help) but rather, any set of numbers that
> looks like an IP address.
Why /not/ grep?
egrep -o '\<[0-9]{1,3}(\.[0-9]{1,3}){3}\>'
does a decent job, though it will match invalid components like your 456
or 789 above. A more thorough regex could be constructed to match
exactly 0-255, but it's somewhat painful.
--
HTH,
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
More information about the vox-tech
mailing list