-4

This question already has an answer here:

Emplyoyee Information:

Name    Age   DOB
______  ___   _________
Jones   54    06/12/1998 
Allen   50    06/09/1990

I want to see the above output in a table.

marked as duplicate by Rui F Ribeiro, Kusalananda, schily, Jeff Schaller, slm shell-script Aug 12 '18 at 14:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You can send a HTML email with a table. Otherwise, the result depends on the font the recipient uses to display the email. – RalfFriedl Aug 12 '18 at 12:06
  • 2
    How is Jones 54 years old if he was born in 1998? – Jesse_b Aug 12 '18 at 12:18
  • 2
    please try to ask a clear question. 1- what do you need, 2- what are your input , 3- what are your expected – Hossein Vatani Aug 12 '18 at 12:33
1

Using html as RalfFriedl suggested:

<table>
  <tr>
    <th>Name</th>
    <th>Age</th>
    <th>DOB</th>
  </tr>
  <tr>
    <td>Jones</td>
    <td>54</td>
    <td>06/12/1998</td>
  </tr>
  <tr>
    <td>Allen</td>
    <td>50</td>
    <td>06/09/1990</td>
  </tr>
</table>

In order to send an HTML email using something like sendmail you need to have an html email header. For this I use a temp file to store the contents like this:

mailto=to@address.com
mailfrom=from@address.com
mailsub='This is the subject of my email'
curdate=$(date "+%a, %d %b %Y %H:%M:%S %z")
html_header="From: <${mailfrom}>\nTo: <${mailto}>\nSubject: ${mailsub}\nDate: <${curdate}>\nContent-Type: text/html; charset=utf-8\n"
echo -e "$html_header" > tmp_file

This will create a header like:

From: <from@address.com>
To: <to@address.com>
Subject: This is the subject of my email
Date: <Sun, 12 Aug 2018 12:30:17 +0000>
Content-Type: text/html; charset=utf-8

You can then add your table to the file and cat tmp_file | mail -t

0

1) As ascii:

#!/bin/bash
prtline(){
    printf "%-10.10s %3.3s %12.12s\n" $1 $2 $3
}

prtline Name Age DOB
prtline _______ __________ ___________
prtline Jones 54 06/12/1998
prtline  Allen 50 06/09/1990

2) As html-table:

echo "<table>"
echo "<tr><td>Name</td><td>Age</td><td>DOB</td></tr>"
echo "<tr><td>Jones</td><td>22</td><td>1821</td></tr>"
#etc
echo "</table>"

3) with tbl/groff/ps2pdf. This will give you predictable nice results, but may be a bit more complicated. You would have to send the pdf as an attachment.

0

Use the below code to convert the CSV file into HTML:

Install nawk to use this code

nawk 'BEGIN{
FS=","
print  "<p>Hi,<br/><br/>"
print  "Please find the Employee details.<p>"
print  "<HTML>""<TABLE border="1"><TH>Name</TH><TH>Age</TH><TH>DoB</TH>" 
}
 {
printf "<TR>"
for(i=1;i<=NF;i++)
printf "<TD>%s</TD>", $i
print "</TR>"
 }
END{
print "</TABLE>"
print "<p><br/>Thank You,<br/>"
print "Team HR<p>"
print "</BODY></HTML>"
 }
' employeedetails.csv > employeeDetails.html

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