1

I have command whose outout is as below: I want its output to be mailed in tabular Html format.

Barcode , %Used , Retention , Pool , State 


000118L7, 36%, expired, UKOffices_Weekly , E 
000126L7, 2%, expired, UKOffices_Weekly , E 
000127L7, 3%, expired, UKOffices_Weekly , E 
000128L7, 50%, expired, UKOffices_Weekly , E 

Expected output

enter image description here

Please help.

1 Answer 1

1

Could you please try following, written and tested with provided samples only. In case your real data is different then you could still take this as a starting point.

awk '
BEGIN{
  s1="\""
  FS=", "
  print "<html>" ORS "<title>" ORS "Storage report" ORS\
  "</title>" ORS "<head>" ORS "<style>" ORS "table, th,\
 td {" ORS "  border: 1px solid black;" ORS "\
  border-collapse: collapse;" ORS "}" ORS "th {"\
 ORS "  background-color: #00ff00;" ORS "}" ORS\
 "</style>" ORS "</head>" "<body>" ORS "<table  border=" s1 "1" s1 ">"
}
FNR==1{
  print "<tr>"
  for(i=1;i<=NF;i++){
    printf("%s%s","<th>"$i"</th>",i==NF?ORS:OFS)
  }
  print "</tr>"
  next
}
{
  print "<tr>"
  for(i=1;i<=NF;i++){
    printf("%s%s","<td>"$i"</td>",i==NF?ORS:OFS)
  }
  print "</tr>"
}
END{
  print "</table>" ORS "</body>" ORS "<html>"
}
'  Input_file

Above code will generate following HTML code:

<html>
<title>
Storage report
</title>
<head>
<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}
th {
  background-color: #00ff00;
}
</style>
</head><body>
<table  border="1">
<tr>
<th>Barcode </th> <th>%Used </th> <th>Retention </th> <th>Pool</th> <th>State</th>
</tr>
<tr>
<td>000118L7</td> <td>36%</td> <td>expired</td> <td>UKOffices_Weekly </td> <td>E</td>
</tr>
<tr>
<td>000126L7</td> <td>2%</td> <td>expired</td> <td>UKOffices_Weekly </td> <td>E</td>
</tr>
<tr>
<td>000127L7</td> <td>3%</td> <td>expired</td> <td>UKOffices_Weekly </td> <td>E</td>
</tr>
<tr>
<td>000128L7</td> <td>50%</td> <td>expired</td> <td>UKOffices_Weekly </td> <td>E</td>
</tr>
</table>
</body>
<html>

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.