-2

I have the script output like below.

Current result:

Filename Destname rowcount bytesize
file1 default 1488 2248
file2 default 123 657
file3 default 123 456
file4 default 567 124

Actual result to be like below (if possible with borders):

Filename  Destname  rowcount  bytesize
file1     default   1488      2248
file2     default   123       657
file3     default   123       456
file4     default   567       124

I need to mail above content in same format.

6
  • 1
    This (to my eyes) is already a table with proper indentation.
    – 4ae1e1
    Jan 3, 2016 at 5:31
  • 1
    What specific table format do you have in mind? For example, are you looking to put | vertical | lines | in | between | each | column?
    – jkdev
    Jan 3, 2016 at 5:33
  • 3
    Please be more specific and attach what you have already tried, see How to Ask. Additionally, bash and PowerShell are radically differing shell languages, please be specific about which shell you're asking about.
    – rivy
    Jan 3, 2016 at 5:54
  • current I am getting this content with out proper indentation. Its like a single row with out any spaces.
    – Thej
    Jan 3, 2016 at 6:57
  • 1
    yes. its fine with HTML.
    – Thej
    Jan 3, 2016 at 7:18

1 Answer 1

2
#!/bin/bash

input="/path/to/your/file.txt"
tmpfile="/path/to/tmpfile.html"

echo 'Content-Type: text/html; charset="us-ascii" ' > "$tmpfile"
awk 'BEGIN{print "<html><body><table border=1>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table></body></html>"}' "$input" >> "$tmpfile"
mail -s "test" [email protected] < "$tmpfile"

Source: http://www.unix.com/302556864-post5.html

0

Your Answer

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

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