Path: utzoo!attcan!uunet!mcvax!dik From: dik@cwi.nl (Dik T. Winter) Newsgroups: comp.unix.wizards Subject: Re: grep "sorted file" inappropriate (was Re: new grep) Message-ID: <7573@boring.cwi.nl> Date: 2 Jul 88 17:37:01 GMT References: <16237@brl-adm.ARPA> <4219@mtgzz.att.com> <199@elgar.UUCP> <2561@homxc.UUCP> <10132@tekecs.TEK.COM> Organization: CWI, Amsterdam Lines: 26 In article <10132@tekecs.TEK.COM> andrew@frip.gwd.tek.com (Andrew Klossner) writes: > [] > > "How about an option (only applicable when patterns start with > "^") to tell grep that the file is lexically sorted (?what > order?) so it can terminate if the input line is lexically > greater than the pattern (s). This is useful for searching > through sorted lists (files, dictionaries, etc...)" > > If your pattern is a string (no meta-characters), what you really want > is a binary search, as implemented by the Berkeley look(1) command. > This is a different sort of operation than grep's sequential search, > and offering it as a separate command makes sense. > > If your pattern contains meta-characters, its position in a sorted list > isn't necessarily defined. For example, when do you stop searching > when the pattern is "^.rwx"? You could define rules that specify when > to stop searching for each of several different forms of pattern, based > on the existing pattern algebra, but this starts to be more complexity > than the problem merits. > And also, ^ at the start of a pattern has already a meaning. -- dik t. winter, cwi, amsterdam, nederland INTERNET : dik@cwi.nl BITNET/EARN: dik@mcvax