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

Clash 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?
bash grep wildcards
add a comment |Â
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?
bash grep wildcards
Does your file have special characters that might make it look like just 31 lines when output to a terminal? What if you pipe tolessorvim -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
add a comment |Â
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?
bash grep wildcards
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?
bash grep wildcards
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 tolessorvim -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
add a comment |Â
Does your file have special characters that might make it look like just 31 lines when output to a terminal? What if you pipe tolessorvim -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
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
lessorvim -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