Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.unix.wizards Subject: Re: what should egrep '|root' /etc/passwd print? Message-ID: <410@quintus.UUCP> Date: 16 Sep 88 00:35:03 GMT References: <44414@beno.seismo.CSS.GOV> <68203@sun.uucp> <8202@alice.UUCP> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 30 In article <8202@alice.UUCP> andrew@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?)