Bash, get the body of the email from a text file, including email

I have several files in a folder, and each of them has one email message. Each message has a header in the format

Subject: formatting fonts To: XXX@XXX.COM From: sender email body 

How can I get the body? I can get an item from something like "read XX" .. Since there is no tag like "Body": I can not get the body of the email at the moment

Any help would be appreciated.

+4
source share
4 answers

You want everything except the first paragraph. sed can do this:

 sed '1,/^$/d' file.txt 

What he says is the beginning at the beginning, ( 1 ), go to the first line where the space ( ^$ - has nothing between the beginning ^ and end $ ) and removes it ( d ).

+8
source

The header and body of the message are always separated by one blank line. You need to read (and ignore) all lines until you see an empty line. The rest of the file is the body.

+1
source

This solution uses pcregrep and matches the subject, in and out of lines, and then gets the opposite of this match.

 pcregrep -M -v 'Subject.*\nTo.*\nFrom.*\n' file.txt 
0
source

send message to:

 | formail -I '' 

part of the procmail package.

0
source

Source: https://habr.com/ru/post/1432826/


All Articles