Why does grep not return the from line?

0

Asked on another forum - no answer yet so I thought I would ask here. I had to escape the backslashes in the grep lines to make the backslash show up in this post.

I have this but grep is not returning the from line. It is something to do with the relay= part of the line. If I modify it to say relay=exampleXXX111.examplf.ex.examplf.com, it outputs the line just fine.

There are other ways to get this info, but I would like an explanation for this specific example.

echo "Apr 4 05:00:24 example sendmail[3365]: x3440OxC003366: from=, size=10181, class=0, nrcpts=1, msgid=<4E94014993C44528C502E32E3239E0B@example.XX.example.com>, proto=SMTP, daemon=MTA, relay=exampleXXX111.examplf.ex.example.com [10.100.10.10]" | grep -v "to=.*\.example\.com"

NO OUTPUT


echo "Apr 4 05:00:24 example sendmail[3365]: x3440OxC003366: from=, size=10181, class=0, nrcpts=1, msgid=<4E94014993C44528C502E32E3239E0B@example.XX.example.com>, proto=SMTP, daemon=MTA, relay=exampleXXX112.examplf.ex.examplf.com [10.100.10.10]" | grep -v "to=.*\.example\.com"

OUTPUT:

Apr 4 05:00:24 example sendmail[3365]: x3440OxC003366: from=, size=10181, class=0, nrcpts=1, msgid=<4E94014993C44528C502E32E3239E0B@example.XX.example.com>, proto=SMTP, daemon=MTA, relay=exampleXXX112.examplf.ex.examplf.com [10.100.10.10]

Mikmikmikmik

Posted 2019-04-08T09:55:57.710

Reputation: 1

1Please do some formatting according to the guidelines. – davidbaumann – 2019-04-08T10:04:38.063

Answers

0

Your first example contains proto= SMTP, ... ex .example.com, so the grep condition is triggered and the -v will suppress the line.

Using grep -v '\sto=.*.example.com' should do the trick.

Eugen Rieck

Posted 2019-04-08T09:55:57.710

Reputation: 15 128

I did not see that, must have had my beer goggles on. Thank you for that. – Mikmikmikmik – 2019-04-08T10:31:41.667