Ray
Ray

Reputation: 21

Shell script Email bad formatting?

My script is perfectly fine and produce a file. The file is in plain text and is formatted like how (My expect results should look like this.) is formatted. However when I try to send my file to my email the formatting is completly wrong.

The line of code I am using to send my email.

cat ReportEmail | mail -s 'Report' [email protected]

The result I am getting on my email.

 30129                 22.65        253
 96187                 72.32            294
109525                 82.35            295
 10235               7.7            105
  5906              4.44            106
 76096                 57.22            251

My expect results should look like this.

 30129                 22.65            253
 96187                 72.32            294
109525                 82.35            295
 10235                   7.7            105
  5906                  4.44            106
 76096                 57.22            251

Upvotes: 0

Views: 139

Answers (1)

John1024
John1024

Reputation: 113844

Your source file achieves the column alignment by using a combination of tabs and spaces. The width assigned to a tab, however, can vary from program to program. Widths of 4, 5, or 8 spaces, for example, are common. If you want consistent formatting in plain text from one viewer to the next, use only spaces.

As a workaround, you can expand the the tabs to spaces before passing the file to mail using the expand utility:

expand -t 8 ReportEmail.txt | mail -s 'Report' [email protected]

The option -t 8 tells expand to treat tabs as 8 spaces wide. Change the 8 to whatever number consistently makes the format in ReportEmail.txt work properly.

Upvotes: 1

Related Questions