grepping with two arguments and piping through sendemail gives additional unwanted data not shown when just grepping

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












This is an odd one. I have a text file of about 5MB that's generated through a unison pipe to a log. If I search the log like this it's fine:



grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log


I'll get the expected output to screen, which is 31 lines long. However, I want to send this output to a departments email. Due to sendemail being fussy about what you can put in it's message field I cannot do the following due "" and I cannot work out how to escape them with sendemail:



sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -m "$(grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log)" -s emailserver


Instead I'm doing:



grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log | sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver


When I do this I get the email but it contains a lot of the text file I ran grep against that it shouldn't be sending, it's not the same grep output. It has the first 15 lines, a lot of text that the grep shouldn't match, then the remainder at the bottom. The annoying part is that if I just do a search for a single data string it works perfectly:



grep -A1 -B1 fail /var/log/csync/logfile_20180720000001.log | sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver


or



sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver -m "$(grep -A1 -B1 fail /var/log/csync/logfile_20180720000001.log)"


Anyone have any ideas?







share|improve this question



















  • Does your file have special characters that might make it look like just 31 lines when output to a terminal? What if you pipe to less or vim - instead? Do you see the same 31 lines?
    – muru
    Jul 20 at 8:45










  • Aha! Pipe through less and I get a raft of crud as it's escaped with ^M. These lines don't show in the terminal. Any idea how to deal with those with the grep command?
    – g33kphr33k
    Jul 20 at 10:07

















up vote
0
down vote

favorite












This is an odd one. I have a text file of about 5MB that's generated through a unison pipe to a log. If I search the log like this it's fine:



grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log


I'll get the expected output to screen, which is 31 lines long. However, I want to send this output to a departments email. Due to sendemail being fussy about what you can put in it's message field I cannot do the following due "" and I cannot work out how to escape them with sendemail:



sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -m "$(grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log)" -s emailserver


Instead I'm doing:



grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log | sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver


When I do this I get the email but it contains a lot of the text file I ran grep against that it shouldn't be sending, it's not the same grep output. It has the first 15 lines, a lot of text that the grep shouldn't match, then the remainder at the bottom. The annoying part is that if I just do a search for a single data string it works perfectly:



grep -A1 -B1 fail /var/log/csync/logfile_20180720000001.log | sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver


or



sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver -m "$(grep -A1 -B1 fail /var/log/csync/logfile_20180720000001.log)"


Anyone have any ideas?







share|improve this question



















  • Does your file have special characters that might make it look like just 31 lines when output to a terminal? What if you pipe to less or vim - instead? Do you see the same 31 lines?
    – muru
    Jul 20 at 8:45










  • Aha! Pipe through less and I get a raft of crud as it's escaped with ^M. These lines don't show in the terminal. Any idea how to deal with those with the grep command?
    – g33kphr33k
    Jul 20 at 10:07













up vote
0
down vote

favorite









up vote
0
down vote

favorite











This is an odd one. I have a text file of about 5MB that's generated through a unison pipe to a log. If I search the log like this it's fine:



grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log


I'll get the expected output to screen, which is 31 lines long. However, I want to send this output to a departments email. Due to sendemail being fussy about what you can put in it's message field I cannot do the following due "" and I cannot work out how to escape them with sendemail:



sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -m "$(grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log)" -s emailserver


Instead I'm doing:



grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log | sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver


When I do this I get the email but it contains a lot of the text file I ran grep against that it shouldn't be sending, it's not the same grep output. It has the first 15 lines, a lot of text that the grep shouldn't match, then the remainder at the bottom. The annoying part is that if I just do a search for a single data string it works perfectly:



grep -A1 -B1 fail /var/log/csync/logfile_20180720000001.log | sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver


or



sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver -m "$(grep -A1 -B1 fail /var/log/csync/logfile_20180720000001.log)"


Anyone have any ideas?







share|improve this question











This is an odd one. I have a text file of about 5MB that's generated through a unison pipe to a log. If I search the log like this it's fine:



grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log


I'll get the expected output to screen, which is 31 lines long. However, I want to send this output to a departments email. Due to sendemail being fussy about what you can put in it's message field I cannot do the following due "" and I cannot work out how to escape them with sendemail:



sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -m "$(grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log)" -s emailserver


Instead I'm doing:



grep -A1 -B1 "Nothing|fail" /var/log/csync/logfile_20180720000001.log | sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver


When I do this I get the email but it contains a lot of the text file I ran grep against that it shouldn't be sending, it's not the same grep output. It has the first 15 lines, a lot of text that the grep shouldn't match, then the remainder at the bottom. The annoying part is that if I just do a search for a single data string it works perfectly:



grep -A1 -B1 fail /var/log/csync/logfile_20180720000001.log | sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver


or



sendemail -f noreply@email.com -t dept@email.com -u NFS Replication Report -s emailserver -m "$(grep -A1 -B1 fail /var/log/csync/logfile_20180720000001.log)"


Anyone have any ideas?









share|improve this question










share|improve this question




share|improve this question









asked Jul 20 at 8:27









g33kphr33k

1




1











  • Does your file have special characters that might make it look like just 31 lines when output to a terminal? What if you pipe to less or vim - instead? Do you see the same 31 lines?
    – muru
    Jul 20 at 8:45










  • Aha! Pipe through less and I get a raft of crud as it's escaped with ^M. These lines don't show in the terminal. Any idea how to deal with those with the grep command?
    – g33kphr33k
    Jul 20 at 10:07

















  • Does your file have special characters that might make it look like just 31 lines when output to a terminal? What if you pipe to less or vim - instead? Do you see the same 31 lines?
    – muru
    Jul 20 at 8:45










  • Aha! Pipe through less and I get a raft of crud as it's escaped with ^M. These lines don't show in the terminal. Any idea how to deal with those with the grep command?
    – g33kphr33k
    Jul 20 at 10:07
















Does your file have special characters that might make it look like just 31 lines when output to a terminal? What if you pipe to less or vim - instead? Do you see the same 31 lines?
– muru
Jul 20 at 8:45




Does your file have special characters that might make it look like just 31 lines when output to a terminal? What if you pipe to less or vim - instead? Do you see the same 31 lines?
– muru
Jul 20 at 8:45












Aha! Pipe through less and I get a raft of crud as it's escaped with ^M. These lines don't show in the terminal. Any idea how to deal with those with the grep command?
– g33kphr33k
Jul 20 at 10:07





Aha! Pipe through less and I get a raft of crud as it's escaped with ^M. These lines don't show in the terminal. Any idea how to deal with those with the grep command?
– g33kphr33k
Jul 20 at 10:07
















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457377%2fgrepping-with-two-arguments-and-piping-through-sendemail-gives-additional-unwant%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457377%2fgrepping-with-two-arguments-and-piping-through-sendemail-gives-additional-unwant%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)