procmail
[Top] [All Lists]

Re: script with sed

2000-10-04 09:32:26
When Collin had this:

P>     :0h
P>     NewSubj=| formail -czXSubject: | head -1 | sed -e 's/\*-.*$//'
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

and I suggested this substitution to save one process:

T>                   formail -czuXSubject:

Dallman replied,

R> Interesting.  Even if there were no -u option to formail
R> (wich I frankly hadn't noticed before, so I found this
R> valuable), one could also have used sed for the same:

I realized that later; generally it makes no sense to pipe head or grep to
sed nor sed to head or grep, because sed can do both jobs.

However, I disagree with Dallman's implementation:

     :0hi
R>   |  NewSubj=| formail -czXSubject: | sed -e '2,$ d' -e 's/\*-.*$//'

This sed code is better:
                                         sed -e 's/\*-.*$//' -e 1q

(Note the `i' flag on the recipe.)  This way sed gets to quit after one line
instead of having to read and discard the rest of the input (if there are
more than one Subject header).  (Since formail will read the entire head,
is the `i' flag necessary?  Well, it won't hurt.)


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>