grep "sorted file" inappropriate (was Re: new grep)
Andrew Klossner
andrew at frip.gwd.tek.com
Sat Jul 2 17:29:39 AEST 1988
[]
"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.
-=- Andrew Klossner (decvax!tektronix!tekecs!andrew) [UUCP]
(andrew%tekecs.tek.com at relay.cs.net) [ARPA]
More information about the Comp.unix.wizards
mailing list