what should egrep '|root' /etc/passwd print?
Richard A. O'Keefe
ok at quintus.uucp
Fri Sep 16 10:35:03 AEST 1988
In article <8202 at alice.UUCP> andrew at alice.UUCP (Andrew Hume) writes:
>it is true that youhave to think carefully about null regular expressions.
Right.
...
>i think that it is clear that grep '' file is always a syntax error;
>there is no useful interpretation of such a regular expression.
Wrong.
(1) The empty r.e. is the mathematically obvious way of writing a
pattern which matches the empty string.
(2) grep -c '' file - print the number of lines in the file
grep -n '' file - print lines with line numbers
ls | egrep '\.c(|\.BAK)$' - find *.c and *.c.BAK files
The first two of these work fine in SunOS 3.2, the last one is the
one I would really like, and it gets a syntax error. There are
several things I could do to make it acceptable, but why should I?
It's clear as it stands, and csh would let me use *.c{,.BAK} as a
pattern.
It is true that the System V version of grep is broken here: if
you try "grep -c '' file" you are told
grep: RE error 41: No remembered search string
which is absurd. In order to write a pattern which will match the
empty string, you are obliged to write something like
grep -c 'x\{0\}' file
It's crazy to allow a complicated hack like this but not the
direct expression of the idea. (Why is the \{..\} feature in
grep, but not in egrep?)
More information about the Comp.unix.wizards
mailing list