grep replacement

Andrew Burt aburt at isis.UUCP
Wed Jun 1 14:17:06 AEST 1988


I'd like to see the following enhancements in a grepper:

	-  \< and \> to match word start/end as in vi, with -w option
		as in BSD grep to match pattern as a word.

	- \w in pattern to match whitespace (generalization: define
		\unused-letter as a pattern; or allow full lex capability).

	- way to invert piece of pattern such as: grep foo.*\^bar\^xyzzy
		with meaning as in: grep foo | grep -v bar | grep -v xyzzy
		(or could be written grep foo.*\^(bar|xyzzy) of course).

	-  Select Nth occurrence of match (generalization: list of
		matches to show: grep -N -2,5-7,10- ... to grab up to the 2nd,
		5th through 7th, and from the 10th onward).

	- option to show lines between matches (not just matching lines)
		as in: grep -from foo -to bar ... meaning akin to
		sed/ed's /foo/,/bar/p.  (But much more useful with other
		extensions).

	- Allow matching newlines in a "binary" (or non-text) sort of mode:
		grep -B 'foo.*bar'  finds foo...bar even if they are
		not on the same line.  (But printing the "line" that
		matches wouldn't be useful anymore, so just printing the
		matched text would be better.  Someone wanting lines could
		look for \n[^\n]*foo.*bar[^\n]*\n, though a syntax to
		make this easier might be in order.  Perhaps this wouldn't
		be an example of a binary case -- but a new character
		with meaning like '.' but matching ANY character would work:
		if @ is such a character then "grep foo@*bar".   Perhaps
		a better example, assuming the \^ for inversion syntax
		above would be "grep foo@*(\^bar)bar -- otherwise it would
		match from first foo to last bar, while I might want from
		first foo to first bar.)

	- provide byte offset of start of match (like block number or
		line number) useful for searching non-text files.

	- Provide a lib func that has the RE code in it.

	- Install RE code in other programs: awk/sed/ed/vi etc.
		Oh for a standardized RE algorithm!
-- 

Andrew Burt 				   			isis!aburt

              Fight Denver's pollution:  Don't Breathe and Drive.



More information about the Comp.unix.wizards mailing list