regex help needed

Björn Lindberg d95-bli at
Fri Oct 15 09:25:02 PDT 2004

Bennett Todd <bet at> writes:

> 2004-10-15T02:36:33 John Galbrit:
> >  --- Bennett Todd <bet at> wrote: 
> > > 
> > > grep '[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*' filename
> > 
> > Thanks! Though for anyone else interested, grep with the -o switch is
> > needed if you just want to extract the IP's only.
> Wow --- I'd never heard of that one, when I wanted to extract just
> the matching pattern I turned to other tools, e.g.
> sed -n '/^.*\([1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\).*$/s//\1/p'
> -o is nice to know about.

I believe it is a new feature. I hadn't heard about it either, and my
slightly aged grep doesn't have it (version 2.4.2). So, even though it
may be convenient it is quite likely not very portable, which is also
nice to know. I usually use sed as well, like you did above.


More information about the lfs-chat mailing list