procmail
[Top] [All Lists]

Re: delete matching line from file

2001-03-11 05:02:25
At 00:15 -0600 11 Mar 2001, tomcat(_at_)visi(_dot_)com wrote:
# remove the original data from data file
:0fwi
 * ^Subject: Re:[  ]+\/.*
      STRINGTOCHECK = $MATCH 
     | sed -e '/$STRINGTOCHECK/d' $HOME/mail_log

Can anyone spot an obvious error?  Using the debug file generated by
procmail doesn't indicate to me what's wrong.

There are several errors here.

- A recipe can have only one action.  You're attempting to use two, a
  variable assignment and a pipe.

- Variable assignment is not an something that can be done on an action
  line (except assigning the output of a pipe to a variable), so here
  STRINGTOCHECK is interpreted as the name of a folder to which the
  message should be saved.

  If logging is enables, procmail should indicate that it ignored an
  extraneous filter-flag (doesn't make sense when saving to a file),
  that it skipped an equal sign followed by the matched text, and that
  the message was saved to a folder named STRINGTOCHECK.

- You used single quotes around a variable in the action line.  This
  will prevent the variable name from being replaced with the value of
  the variable.

- You told procmail that the pipe should be used as a filter, so it will
  replace the message being processed with the output from sed.  This
  output will probably not be a valid message.

- You probably don't want procmail to consider the message as being
  delivered to sed.  This will cause the message to be lost completely.
  To avoid this, you should include the 'c' flag on the recipe.

- Regular expressions in procmail use minimal matching to the left of
  the match operator.  So the `+' modifier on the character class that
  attempts to remove leading white space won't have an effect, all but
  one whitespace character will be included in $MATCH.

  To avoid this, you need to specify that the matched text should start
  with a non-whitespace character.  This also applies to the preceding
  recipe.

- Unless you specifically tell it to do so, sed doesn't modify files.
  The sed command here will print to STDOUT the contents of
  $HOME/mail_log except for any lines that match the literal regular
  expression $STRINGTOCHECK (that exact string, not the *value* of that
  variable).

  Instead, you could use something like (untested):

    | sed -e "/$STRINGTOCHECK/d" $HOME/mail_log > $HOME/mail_log.tmp && \
      mv $HOME/mail_log.tmp $HOME/mail_log

  Notice that you shouldn't use the same file as both input and output.
  If you do, you'll end up with an empty file (the output file gets
  truncated before the input is read).

- You should have procmail use a lockfile when sed is modifying this
  file, as was done on the echo recipe.  Otherwise the file will likely
  get messed up.


So, the complete recipe would look something like:

:0
* ^Subject: Re:[  ]+\/[^        ].*
{
  STRINGTOCHECK = $MATCH

  :0cwi: $HOME/mail_log.$LOCKEXT
  | sed -e "/$STRINGTOCHECK/d" $HOME/mail_log > $HOME/mail_log.tmp && \
    mv $HOME/mail_log.tmp $HOME/mail_log
}

-- 
Aaron Schrab     aaron(_at_)schrab(_dot_)com      http://www.execpc.com/~aarons/
 The "data" for most coffee URIs contain no caffeine.  -- RFC 2324
_______________________________________________
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>