Thanks, Derek. On Mon, Apr 15, 2019 at 12:02:18PM -0500, Derek Martin wrote: > 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.
For sure, I meant to say from a file, and I wrote from a file in other occurrences, but here things got mixed up. I know what I/O redirection is, but that you cannot put a /* when you had a < preceding it, was new to me.Thanks, I take note of your detailed explanation. > > 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. That's by far the most elegant solution, thanks!! I'm at it, and I'll report back to yu as soon as I have set it up with all the variables set. > 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/* > Yes, that's the way we had talked about in the previous message(s). > > 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. I heard of it quite a lot, but I have never used it; it sounds interesting, although the more I read into the mutt manual the more I learn of features I didn't know. For example, the way of monitoring incoming mail. Maybe it would have been more appropriate to use merely mutt with its macros, and not sed, but thinking about more generic use cases of text editing/manipulation it's good to have a thorough knowledge of it.And tomorrow I tell you that I am going to write all my mails with sed. :-) I'll report back. Cheers, felixs > -- > 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. >