2
I'm facing an issue with mails. I need to get all messages between 2 people:
somebody1@domain.com
and person@domain.com
.
The file
:
From: somebody1@domain.com
to: person@domain.com
<body of the message1>
From: somebody2@domain.com
to: person@domain.com
<body of the message1>
From: somebody1@domain.com
to: person@domain.com
<body of the message1>
From: somebody3@domain.com
to: person@domain.com
<body of the message1>
From: somebody5@domain.com
to: person@domain.com
<body of the message1>
I tried to use the following sed
:
sed -n "/From: [Ss]omebody1/,/From: /p" inputfile > test.txt
As a result I got all mails from somebody1 to test.txt
file.
Question is: What should be the structre of sed
to get only mails between somebody1 and person?
Probably you can obtain an output more clean without the first
p;
. Just to avoid a list of isolated matches withFrom: somebody1@domain.com
not followed by the second person match and the block of the letter. – Hastur – 2015-10-13T12:58:15.410@Hastur Good hint, I corrected it, now It's not printing isolated matches anymore – chaos – 2015-10-13T13:11:26.577
Thanks a lot for that. I would like to ask another question: thing is that what i should get in return is whole message body (which may containt new line characters) till next occurence of "From:" Right now i get more info but it's not enough:
example output From: somebody1@domain.com To: person@domain.com Date: Mon, 06 Jul 2015 17:41:03 GMT Subject: *************** Content-type: ********************************* X-Scanned-By: **********************
and no body after it – wtk – 2015-10-13T13:31:47.597
Search for your file the point in which it stops your chunk, and probably you will find another time the keyword
From: somebody1@domain.com
... You have to select a different unique key that you will not find again in the body of your message. It will be the same with theawk
answer. Give it a try too. – Hastur – 2015-10-13T15:09:50.557