-2

echo $d produces output below which is separated by new line after each ';'

REVOKE ALL ON URI 'hdfs://nameservice/data/ed_bos_reporting_stg' FROM ROLE ed_bos_reporting; 
REVOKE ALL ON URI 'hdfs://nameservice/data/fq' FROM ROLE ed_edw_telephony_rw; 
REVOKE ALL ON URI 'hdfs://nameservice/data/fq' FROM ROLE edw_rw; 
REVOKE ALL ON URI 'hdfs://nameservice/data/standard_register_mail_piece' FROM ROLE standard_register_mail_piece_rw; 
REVOKE ALL ON URI 'hdfs://nameservice/data/tenant/ed_edw/LSFE_CDC/target_files' FROM ROLE edw_rw; 
REVOKE ALL ON URI 'hdfs://nameservice/data/tenant/ed_standard_register_mail_piece_stg' FROM ROLE ed_standard_register_mail_piece_rw;

When I pipe $d in the mail command -

echo "$d" | mail -s "subject" -r "Name<Name@somewhere.com >" first.last@somewhere.com

The results are not separated by a new line.

I have tried:

echo -e "$d\n" | mail -s "subject" -r "Name<Name@somewhere.com >"
echo -e "$d" $'\n' | mail -s "subject" -r "Name<Name@somewhere.com >"

And few others with no luck. Any suggestions/leads to documentation would be appreciated.

UPDATE This does work fine in gmail. However not in Outlook

TheNewGuy
  • 559
  • 1
  • 10
  • 27

3 Answers3

1

It seems that Outlook removed extra line breaks from my message. I was able to use awk to fix the problem.

echo "$d" | awk '{ print $0"   " }' | mail -s "subject" -r "Name<Name@somewhere.com >" first.last@somewhere.com

This reads every single line, and re-prints it with three spaces at the end. Outlook is now happy. https://blog.dhampir.no/content/outlook-removes-extra-line-breaks-from-plain-text-emails-how-to-stop-it

TheNewGuy
  • 559
  • 1
  • 10
  • 27
  • Happy to hear that you solved the problem. You can accept your own answer to mark your questions as solved. By the way: `echo "$d" | ...` can be written as `... <<< $d`. You could even replace `awk` with bash's parameter substitution: `mail ... <<< "${x/$'\n'/...$'\n'}"` (replace the `...` with three spaces. Stackoverflow merges multiple spaces in inline code). – Socowi Jun 20 '18 at 19:03
0

I don't have outlook and cannot test my assumptions, but maybe outlook requires the text to use \r\n line endings instead of just \n line endings.

Try

sed $'s/$/\r/' <<< "$d" | mail ...

or install dos2unix and use

unix2dos <<< "$d" | mail ...

to convert the linux \n line endings into windows \r\n line endings.

Socowi
  • 25,550
  • 3
  • 32
  • 54
  • This results in the report being sent as binary attachment. – TheNewGuy Jun 20 '18 at 18:06
  • 1
    @user3508766 Too bad. Anyway, I found some [other answers](https://stackoverflow.com/a/22098987/6770384) that might help you. They include using only `\r` (try `tr '\n' '\r' <<< "$d" | mail ...`) or writing two spaces in front of each new line and using `mailx`. – Socowi Jun 20 '18 at 18:52
-1

if you have output that you'd like separated by newlines on a certain character, tr is pretty good about that:

echo "$d" | \
mail -s "subject" -r "Name<Name@somewhere.com >" first.last@somewhere.com | \
tr ';' $'\n'

This will remove the semicolons. I am sure there's a way to do it without removing them but this is the only way I know off the top of my head; HTH

jeremysprofile
  • 10,028
  • 4
  • 33
  • 53