Adam Grove asked,
| When I have recipes search for patterns in the body of a message,
| I'd like to limit how many lines (or bytes, it doesn't really
| matter much) into the message the search is performed.
| That is, I'd like every match appearing after some line N, for
| a value of N I specify, to just be ignored.
|
| Does anyone have a (hopefully efficient) way of doing this?
If N had been small, say 6 as in a previous thread about this, I'd
suggest this, which allows for up to five (6 - 1) previous lines;
leave out the last ".*" just before "pattern" if the pattern is
left-anchored:
:0B
* ^^(.*$(.*$(.*$(.*$(.*$)?)?)?)?)?.*pattern
whatever
or something like that; I actually answered
:0B
* ^^(.*$)?(.*$)?(.*$)?(.*$)?(.*$)?.*pattern
whatever
at the time but someone who knows procmail's innards better than I said
that the nested version, while harder to type, is more efficient. One
could also do this if N=6:
:0B
* ^^(.*$)?(.*$)?(.*$.*$.*$)?.*pattern
whatever
or
:0B
* ^^(.*$)?(.*$.*$)?(.*$.*$)?.*pattern
whatever
But if N=50, to heck with it:
:0Bi
toplines=| head -$N # sed ${N}q if you don't have head
:0a
* toplines ?? pattern
whatever
There were some other methods, but they could run into LINEBUF trouble,
so I won't bring them up again.