Convert shell script output txt file to html table


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert shell script output txt file to html table
# 1  
Old 09-19-2011
Convert shell script output txt file to html table

Hi,

I have script which generates the output as below:

Code:
Jobname Date           Time        Status
abc        12/9/11       17:00      Completed
xyz         13/9/11       21:00      Running

I have the output as a text file. I need to convert it into a HTML Table and sent it thru email

Thanks
# 2  
Old 09-19-2011
Code:
kent$  echo "Jobname Date Time Status
abc 12/9/11 17:00 Completed
xyz 13/9/11 21:00 Running"|awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}'
<table>
<tr>
<td>Jobname</td>
<td>Date</td>
<td>Time</td>
<td>Status</td>
</tr>
<tr>
<td>abc</td>
<td>12/9/11</td>
<td>17:00</td>
<td>Completed</td>
</tr>
<tr>
<td>xyz</td>
<td>13/9/11</td>
<td>21:00</td>
<td>Running</td>
</tr>
</table>

# 3  
Old 09-19-2011
Hi sk1418,

Thanks for your suggestion.

Is there a way to get the input directly from the txt file instead of coding it.
# 4  
Old 09-19-2011
yes.. use..
Quote:
awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' <filename>
so simple Smilie
# 5  
Old 09-20-2011
Hi,

With your suggestions i created the below script but the output email just has tags not the table view. Please help..
Code:
#!/bin/bash

echo 'Content-Type: text/html; charset="us-ascii" ' >> email.html

echo "<html>" >> email.html

echo "<Body>" >> email.html

awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' test >> email.html

echo "</Body>" >> email.html

echo "</html>" >> email.html

mail -s "test" abc@xyz.com < email.html


Last edited by Franklin52; 09-20-2011 at 03:16 AM.. Reason: Please use code tags, thank you
# 6  
Old 09-20-2011
You should use the actual input file as you have shown in #1.
the content of the file should be like this.

Code:
Jobname Date Time Status
abc 12/9/11 17:00 Completed
xyz 13/9/11 21:00 Running

# 7  
Old 09-20-2011
you need to use sendmail utility to send email in html format.

Try the below code, instead of mail command

Code:
 
(
echo "From: abcd@abcd.com "
echo "To: abcd@abcd.com "
echo "MIME-Version: 1.0"
echo "Subject: Test HTML e-mail." 
echo "Content-Type: text/html" 
cat email.html
) | sendmail -t

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

2. Shell Programming and Scripting

Convert shell script output txt file to html table

My concnern related to the post -Convert shell script output txt file to html table, in this how to print the heading as color. awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' <filename> (8 Replies)
Discussion started by: sarajobmai
8 Replies

3. UNIX for Dummies Questions & Answers

Convert Txt file to HTML table and email

Hi all I need help converting a text file into a html table in bash and I need to email this table. The text file looks like the below. Two columns with multiple rows. Top row being header. Application Name Application Status Application 1 Open Application 2 ... (2 Replies)
Discussion started by: hitmanjd
2 Replies

4. Shell Programming and Scripting

[Solved] Shell script output in HTML or with table like results and mail

Hello, Currently i have a script which will disply the results in plain text format. I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html and send that content as email. Please help me how i can do that. I am using... (10 Replies)
Discussion started by: joy lobo
10 Replies

5. Shell Programming and Scripting

Need to convert output.txt into html file

I have output.txt file generated through shell scripts which need convert in tabular format using html can you please help me output.txt Token State Date1 Date2 Description Name 34567 open 27/06/13 28/06/13 ... (5 Replies)
Discussion started by: vijay_rajni
5 Replies

6. UNIX for Dummies Questions & Answers

How to Update DB table from txt file using CRONJOB in Unix Shell Script

Hi Experts, can guide how we can Update a Database Table using a txt file source Using Unix Shell Scripts. What are the Cron Jobs codes can written to Update DB table. txt file contains record like data. US 09/03/2012 User DocType DocID. these above feilds in txt files need to be updated in... (4 Replies)
Discussion started by: mahesh.sap
4 Replies

7. Shell Programming and Scripting

Bash shell script that inserts a text data file into an HTML table

hi , i need to create a bash shell script that insert a text data file into an html made table, this table output has to mailed.I am new to shell scripting and have a very minimum idea of shell scripting. please help. (9 Replies)
Discussion started by: intern123
9 Replies

8. Shell Programming and Scripting

shell script output in HTML or with table like results

Hello, Currently i have a ksh script which will disply the results in plain text format. I want to format the result in more readable format like Making bold headings and format with colors etc. Something like html or excel format and send that content as email. Please help me how i can do... (2 Replies)
Discussion started by: kotasateesh
2 Replies

9. Shell Programming and Scripting

Is it possible to convert text file to html table using perl

Hi, I have a text file say file1 having data like ABC c:/hm/new1 Dir DEF d:/ner/d sd ...... So i want to make a table from this text file, is it possible to do it using perl. Thanks in advance Sarbjit (1 Reply)
Discussion started by: sarbjit
1 Replies

10. Shell Programming and Scripting

Format txt file as html table

I have a short time to solve a problem, so I need some help. I've searched the forum, but I couldn't find a solution to my problem. I made a script to filter some text and now I have a new requirement to make it available as html table. Problem is that I more than one files with different set... (2 Replies)
Discussion started by: tetreb
2 Replies
Login or Register to Ask a Question