0

All I have is a linux command (I don't know what's behind the command, the script or what formats the command output), so what I can do is to pull the data [which is in table form with invisible column lines], out from linux, and send it out to people for reviewing purpose.

When I run the command, the generated output are nicely formatted in aligned columns on my console screen, even when I put it into diff types of file extension: .txt / .csv / .xls (they are all nice in linux terminal)

thatCommand | mail -s 'Statistics' my@email.com

Above: print output as message body in the email
Below: redirect output to a file and send it out as attachment in email

thatCommand > stat.xls
uuencode stat.xls table.xls | \mail -s "Statistics" my@email.com

Then, I have this problem, after executing the first command line, the table in my message body is shown like below

Student Name ID SubjectA(%) SubjectB(%)
Aaron Frank 7892 89 100
Benjamin Ayres 8892 78 90

How I would like it, to be arranged according to columns:

Student Name       ID   SubjectA(%) SubjectB(%)
Aaron Frank       7892      89         100
Benjamin Ayres    8892      78          90

So I tried 2nd command lines with attachment instead. After receiving those different types of file extension attachment in mail, save and open them in windows. (in my PC, csv and xls are by default open by excel, txt open using notepad)

The output supposed to be in different columns (it's a table in linux before I exported it),
but instead all the data is in the first column, looking messy in excel application. [looking messy in notepad too]

The below image is my endgoal, data values in different columns (well aligned)

how it supposed to look like, how I expect it

how it looked like now, the data are all in columnA only how it looked like now

Is perl script able to help? So that I could get the nicely formatted output when received the attachment? I wouldn't mind because I still have to add some info at the end of the excel file in linux. (even though I have yet to figured out how to do that), but for now my main concern is on how to format it :)

This is the link question what would be further done.

closed as unclear what you're asking by Kusalananda, Satō Katsura, Thomas Nyman, sam, ilkkachu Apr 1 '17 at 14:09

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    not clear, but I think you just need to pipe the output to column -t – Sundeep Mar 20 '17 at 2:25
  • @Sundeep that will only work if the font that the email is rendered as is fixed width (which you can set). You could also use an HTML table. – DarkHeart Mar 20 '17 at 2:36
  • 1
    You could also send the contents as an attachment – DarkHeart Mar 20 '17 at 2:36
  • Hi DarkHeart, I have learned to : echo "testing" | mail -s "Test mail" user@example.com -a Desktop/attempt.txt (this is not working) Do you mean there is a way to send the output from running a command in terminal console window as attachment ? – Santa Mar 20 '17 at 4:02
  • Hi @DarkHeart, I have tried to save the output to both csv and text file, but the output is still the same. Not aligned. Would you shed some light on this? Should I pipe the output into perl script and format from there? – Santa Apr 1 '17 at 9:23
2

First of all, Perl itself can send emails, see here for examples, easier and less error prone.

Anyway, for your case, a HTML email body should work, e.g

<table>
  <tbody>
    <tr>
      <td>Adam</td>
      <td>50</td>
    </tr>
  </tbody>
</table>

And to send HTML emails, you need to set the content-type header, see here for an example

  • thanks daisy! sorry that I wasn't clear in my question. I have a command, then I run it in console terminal to send the output(of the command) to mail, but it was not formatted. so sometimes, I would not know, if that person is Adam and who has that amount of files. – Santa Mar 20 '17 at 3:58
  • The OP is clearly confused.   IMNSHO, you compounded that confusion by making up your own data.   Why didn’t you use the OP’s data from the question (e.g., “Aaron Frank” and 7892)? – Scott Apr 1 '17 at 17:59
  • Hi @Scott, daisy was actually replied by using my previous edited question's data. And I have edited the question in attempt to get people to understand my whole picture. thanks – Santa Apr 1 '17 at 23:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.