I'd like a new feature added to grep to show some characters before and after a match and a way to advance the current position in a line to start matching again.
Conceptually I would like for it to work like the following. Usually grep processes a line at a time. In charcter mode grep reads a line at time and starts at the beginning of a line looking for the regular expression. Call where the regular expression starts matching start and sstart and where it ends end and eend. Add the following options or equivalennt: --char-before-context-regex Print num characters of of leading context after matching a regular expression. --char-after-context-regex Print num characters of trailing context after matching a regular expression. --char-skip-regex EXPLANATION OF HOW THE OPTIONS WORK (This is the start of the character loop.) If --char-before-context-regex is set try to match such that it ends at character start-1. If it matches call the position it starts sstart. If --char-after-context-regex is set try to match such that it starts at character end-1. If it matches call the position it ends eend. Print characters at positions sstart--eend. Beginning at start, try to match --char-skip-regex. If it matches set start to the position of the character after this match and go to "(This is the start of the character loop.)". I've wanted grep to be able to do character context for a long time, looked at the code and said to myself, adding it would be a major undertaking for me because I'm not familiar with the code. If you would add it that would be great. Mark Senn, Systems Programmer, Engineering Computer Network, Purdue University