Re: grep for metacharacters



very strange. have you tried quoting the regex:

grep -c "\t"

you probably know this, but just in case: if you're running this grep
from, say, a bash script, you might have to escape the escape
character:

grep -c \\t

and this can go on ad naseum, e.g., a subshell in a script might need:

`grep -c \\\\t`

also, i should point out that i didn't read your original post close
enough and that i should note a correction to it. "grep -c \t" will
count the number of LINES having a tab character, NOT the number of
tab characters (as you wrote).

lastly, i just ran "grep -c \t" and "egrep -c \t" on RHEL4 with a file
containing tabs and it worked just fine. seems like it's gotta be a
backslash escaping issue, or perhaps your file doesn't have any tabs?


On Tue, 11 Sep 2007 22:02:38 -0400, Tim Boyer <tim@xxxxxxxxxxxxxx> wrote:
On Wed, 12 Sep 2007 01:08:03 +0000 (UTC), Doug Morse <morse@xxxxxxxxx> wrote:

if available, use "egrep" instead


It is; doesn't work.

On Tue, 11 Sep 2007 20:54:52 -0400, Tim Boyer <tim@xxxxxxxxxxxxxx> wrote:
Other Unixes I've used have been able to grep for metacharacters. For
instance, to count the number of tabs in a document, you just do a

grep -c \t

or a \n for newlines, a \f for page feeds, etc.

Apparently, this doesn't work in Linux.

Is there any way to do this?


.



Relevant Pages

  • Re: grep for metacharacters
    ... but just in case: if you're running this grep ... and this can go on ad naseum, e.g., a subshell in a script might need: ... containing tabs and it worked just fine. ... And egrep in RHEL5 doesn't see _any_ of them: ...
    (linux.redhat)
  • grepping for tabs
    ... I searched google a bit, ... Suppose the file '1' words seperated by tabs: ... $ grep '\b8' 1 ... To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org ...
    (Debian-User)
  • Re: grep command and EXACT host entry in /etc/hosts
    ... >> I need grep to only match the word start, ... >> tabs after the word. ... although this will look in the hosts naming database, ... Andrew Gabriel ...
    (comp.unix.solaris)
  • Re: Bash Script Problem
    ... and using tabs instead of spaces. ... at scripting. ... I'll see if I can come up with something that uses grep ... Laura ...
    (linux.redhat)
  • Re: grep for metacharacters
    ... instance, to count the number of tabs in a document, you just do a ... grep -c \t ... or a \n for newlines, a \f for page feeds, etc. ...
    (linux.redhat)