Fritz Feuerbacher asked,
| I am going to have certain people email me ascii text file that will
| have one line at the top which designates who they are by a number.
|
| It will be a line like USER=15
|
| What I need to do is look at this line, get the number 15 from it and make
| sure its within some bounds. Then, once I figure out its valid, I need
| to strip this line from the top of the message, and then write the message
| to a file using the number as part of the file name. I don't need any of the
| header information saved to the file.
|
| I wonder what would be the best thing to use, maybe a perl script or
| maybe just sed or even grep?
Probably none of them, except to strip the line from the message. Say you
have started assigning numbers at 1 and given out successive integers, of
which the highest so far is N.
Some of this code looks a little funny; I don't know Fritz's version of
procmail, so I'm allowing both for (1) versions where you can't extract
from the existing $MATCH without clobbering it and (2) versions that extract
trailing newlines, even though no version of procmail does both.
#caret, caret, left parenthesis, space, pipe, tab, pipe, dollar,
#right parenthesis, asterisk
:0B
* ^^( | |$)*USER=\/[1-9][0-9]*$
{
USERNUMBER=$MATCH
# Strip trailing newline:
:0
* USERNUMBER ?? ^^\/.+
{ USERNUMBER=$MATCH }
MAXNUMBER=N # change N to the actual highest valid number and update
# as needed
:0
* $ $MAXNUMBER^0
* 1^0
* $ -$USERNUMBER^0
routine_for_invalid_numbers # could be a braced block
# Alternatively, you could check for validity this way:
# :0
# * ! USERNUMBER=^^(some regexp to check for currently valid numbers)^^
# routine_for_invalid_numbers
:0b:
| sed "1,/USER=$USERNUMBER/d" >> filenameprefix${USERNUMBER}filenamesuffix
}