On Sun, Apr 14, 2019 at 08:06:04PM +0200, felixs wrote:
> I searched in the documentation of sed (info sed),  the bash-hacker's
> wiki (1) and read through the Advanced Bash Scripting Guide, but I
> haven't found the exact use case of redirecting input to all the files
> of a directory. 

FWIW, you redirect input *from* a source file, not to it.  You
redirect output *to* a destination file.  And you won't find anything
that describes the use case of redirecting a program's input from
multiple files anywhere, because you can't do that.  I/O redirection
is a function of your shell, so if you were to find it, it would be in
the shell's manual, not in sed's.

> But isn't there a way to address all the files in the INBOX? I mean, if
> it were a mbox format, no problem, that's just one file and its content
> can be fed into sed. 

There are three ways to do this (with sed, see below for likely a
better option, depending on exactly what you want to do), and which
one you choose depends on what your goal is.  I *think* they've all
been covered, but this thread has been a little hard for me to follow,
so I'll summarize briefly:

If you want to filter each message individually (putting its output
into one file per message) you have one option: Use the shell to loop
over the files, e.g.

  ls -1 /path/to/spool | while read file; do
    outfile_name = "${file}.out"
    # You can use -e but you don't need it, no difference
    sed -n '/^From: $EMAIL_ADDRESS/p ; /Subject: $SUBJECT/p' "$file" > 
$outfile_name
  done

This uses output redirection, but does NOT use input redirection.
NOTE:  The reason I did it this way is because it properly handles any
file names with spaces or other special characters in them.  There is
some nuance with using ls and specifying /path/to/spool vs.
/path/to/spool/*, but the first is what you would usually want.  This
probably isn't interesting for Mutt mailboxes, but is a better
technique for the general case where your filenames may have spaces or
special characters in them.

If you want to process all the files at once and produce only one
output file, you have 2 options:

1. use cat:

    cat /path/to/spool/* | sed -n ...

2. list the files on the sed command line:

   sed -n ... /path/to/spool/*


> I'd be glad to be able to use this to have sed filter the INBOX for
> mails having arrived from a known sender with a known subject line,
> after mutt has polled for new mail.

FWIW, there may be a better tool for this purpose, depending on
exactly what you're trying to do: Procmail.  It would filter your
messages according to this rule (and many other possible rules you
could create) *before* Mutt sees it, so that Mutt will find it in the
folder you intended it to be delivered to in the first place.  It can
also be used to deliver mail to multiple folders, so that for example
certain messages are delivered to a separate "important" mailbox, but
still delivered to some other mailbox that is applicable to a larger
set of messages.  Related to procmail is formail, which lets you do
things like extract headers from a message.

-- 
Derek D. Martin    http://www.pizzashack.org/   GPG Key ID: 0xDFBEAD02
-=-=-=-=-
This message is posted from an invalid address.  Replying to it will result in
undeliverable mail due to spam prevention.  Sorry for the inconvenience.

Attachment: pgpOsKjDhe5QK.pgp
Description: PGP signature

Reply via email to