[WBEL-users] grep help
Benjamin J. Weiss
Benjamin J. Weiss" <benjamin@birdvet.org
Wed, 15 Dec 2004 06:55:19 -0600 (CST)
On Tue, 14 Dec 2004, William Hooper wrote:
>
> Timothy Nash said:
> [snip]
> > It works for me on my linux box as well. A friend of mine asked me this
> > question - not sure exactly what he's trying to do. I just found out he's
> > using Solaris. Anyone know why Solaris treats periods differently than
> > Linux.
>
> Nope, but...
>
> > When he issues any of the following commands:
> >
> >
> > grep -w "hostname" hosts
> > grep -w 'hostname' hosts
> > grep -w hostname hosts
>
> These commands are correct to return both lines (and in the original
> example, all 4 lines). The command that works is:
>
> grep hostname$ hosts
>
> This works because the "$" is a metacharacter that means "at the end of a
> line". Perhaps the Solaris grep is a different version?
This works if there's no whitespace after the hostname. If he's
accidentally put in tabs or spaces after the line, then the following will
still pick it up:
grep -w hostname[[:blank:]]*$ hosts
Ben