[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep -
From: |
Aharon Robbins |
Subject: |
Re: grep - |
Date: |
Tue, 12 Feb 2008 08:10:02 +0200 |
In article <address@hidden> you write:
>Hello,
>
>not sure if this is a bug or not but here it is:
>
>ypcat hosts | grep st[1-4]-nttd
>
>The above commant should pipe the stout of the ypcat hosts to grep and
>find any thing matching st (range of numbers 1 2 3 4) and ending with
>(-nttd)
>
>To clarify the above command, I'm searching for hostnames that are any
>of the following: st1-nttd, st2-nttd, st3-nttd, or st4-nttd.
>
>Now... if I run the command in any particular directory /, /root, /tmp/
>etc... the commard properly provided a list of all host that met that
>st[1-4]-nttd - which is the four listed above.
>
>However, I unknowingly had an empty file named 'st1-nttd' (a file with
>the same name as one of the hosts I was greping for) while in /root. I
>ran ypcat hosts | grep st[1-4]-nttd, from /root and the output only
>showed 'st1-nttd'.
>
>I had thought I had an NIS problem originally but it turns out, after
>removing the file 'st1-nttd' for /root, and re-running ypcat hosts |
>grep st[1-4]-nttd, the problem was solved. Sounds simple enough but it
>drove me crazy of an entire afternoon.
>
>Is this a bug in grep or am I simply using bad syntax?
>
>Thanks.
>DL
The shell examines command line arguments for patterns to expand.
Thus it expanded the st[1-4]-nttd into st1-nttd. If you
were to quote the pattern
ypcat hosts | grep 'st[1-4]-nttd'
then things will work like you expect.
--
Aharon (Arnold) Robbins arnold AT skeeve DOT com
P.O. Box 354 Home Phone: +972 8 979-0381 Fax: +1 206 202 4333
Nof Ayalon Cell Phone: +972 50 729-7545
D.N. Shimshon 99785 ISRAEL
- grep -, leondd1995, 2008/02/12
- Re: grep -,
Aharon Robbins <=