procmail
[Top] [All Lists]

Re: procmail/sed script for Travelocity fare updates

2001-03-05 13:25:03
Don Hammond <procmail1(_at_)tradersdata(_dot_)com> writes:
...
 :0fbw
 * ^From:(_dot_)*memberservices(_at_)travelocity\(_dot_)com
 * ^Subject: Travelocity.com fare watcher update
 |perl -ne 'print(/(?:FROM|TO):\s*([^(]+)/g);\
 /(\$[\d.,]+).*(-\$[\d.,]+)/ and print "$1 $2\n";'


Note, for some unknown reason I actually did test this and it works, but
only if the perl one-liner is on one line. The line break above is for
readability only. In fact, depending on where I put line breaks (while
playing with this and others) the pipe would either fail or just not
work correctly. If anyone has an explanation for that, maybe this could
be remotely on topic.

When procmail passes commands to the shell, it leaves the
backslash/newline combos in the string it passes to the shell**.
The shell generally strips these out, but it doesn't remove them when
they occur between single-quotes.  So, the action shown above, taken as
is (wrapped), results in a backslash/ newline combo in the argument to
the -e option passed to perl.  Perl doesn't like that.

Since using double quotes instead of single quotes would be to ugly,
the solution is to use two -e options:
        :0fbw
        * ^From:(_dot_)*memberservices(_at_)travelocity\(_dot_)com
        * ^Subject: Travelocity.com fare watcher update
        |perl -ne 'print(/(?:FROM|TO):\s*([^(]+)/g);' \
                -e '/(\$[\d.,]+).*(-\$[\d.,]+)/ and print "$1 $2\n";'


** If a line contains _only_ a backslash, then procmail will leave out
the backslash, thereby passing an unescaped newline to the shell.


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