Convert text file to HTML tabular format.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert text file to HTML tabular format.
# 1  
Old 09-02-2014
Hammer & Screwdriver Convert text file to HTML tabular format.

Please provide script/commands to convert text file to HTML tabular format.

No need of styles and colours, just output and a heading in table is required.

Output file will be send via email and will be seen from outlook.

(script required without using awk).

output file content: (sar command output)

Code:
12:00:01 AM       CPU     %user     %nice   %system   %iowait    %steal     %idle
12:10:01 AM       all      5.99      0.00      3.04     11.76      0.00     79.21
12:20:01 AM       all      7.41      0.00      3.05      7.75      0.00     81.79
12:30:01 AM       all     12.79      0.00      2.87      6.74      0.00     77.60
12:40:01 AM       all     10.77      0.00      2.93      8.70      0.00     77.59

Regards,
Veera

Last edited by Don Cragun; 09-02-2014 at 02:23 PM.. Reason: Add CODE tags.
# 2  
Old 09-02-2014
Hi,

Simpler than using a script, you could use text2html - it's available here.

Regards

Dave
# 3  
Old 09-02-2014
Hello Veera,

Please use code tags as per forum rules for commands and codes which you are using in post. Following may help you to get a file's output in a html format.
I am taking file named test17 as input file.

Code:
Output_File=/tmp/file556
echo "<html>" > $Output_File
echo "<title> Test" >> $Output_File
echo "</title>" >> $Output_File
echo "<body>" >> $Output_File
echo "<table border style="05">" >> $Output_File
 
while read line
do
        echo "<tr>" >> $Output_File
        echo "<td>" >> $Output_File
        echo $line >> $Output_File
        echo "</td>" >> $Output_File
        echo "</tr>" >> $Output_File
done < "test17"
echo "</table>" >> $Output_File
echo "</body>" >> $Output_File
echo "</html>" >> $Output_File
MAILTO=test@test.com
Subject=Test
 
cat - ${Output_File} <<EOF | /usr/sbin/sendmail -oi -t
#From: ${MAILFROM}
To: ${MAILTO}
Subject: $SUBJECT
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
EOF


Thanks,
R. Singh
# 4  
Old 09-03-2014
Thanks R.Singh,

Code works fine, But still you have assigned everything as a row , hence the when I look at the output same issue persists.

sample:
Code:
12:00:01 AM       CPU     %user     %nice   %system   %iowait    %steal     %idle
12:10:01 AM       all     5.99     0.00      3.04     11.76      0.00     79.21
12:20:01 AM      all      7.41     0.00      3.05      7.75      0.00     81.79
Average   12.79      0.00      2.87      6.74      0.00     77.60


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 09-03-2014 at 09:07 AM..
# 5  
Old 09-03-2014
Hi Veera,

Please let me know the expected output for same. So that I can help more on same.

Thanks,
R. Singh
# 6  
Old 09-03-2014
Hi,

You can always try;

Code:
txt2html --make_table --infile "input.txt" --outfile "table.html"

It's quite happy with being included in a script.

Regards

Dave
# 7  
Old 09-03-2014
Expected:
Code:
Col1 col2   Col3
1      2      3

current results:
Code:
Col1 col2 col3
1 2 3

(this is happens when I send the output to email and viewing it through outlook as its convert to calibri format).

In order to display in tabular format I need to use html and sendmail (for oracle queries I go with SET HTML option). But for Unix related output I need to send as a tabular format.


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by Veera_V; 09-05-2014 at 02:34 AM.. Reason: trying to add code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert csv data to html format

I am new to html and need to convert the attached csv file data to html format ; running into issues. please assist. #!/bin/ksh echo "<html>" ; echo "<head><style> table {border-collapse: collapse;} table, td, th {border: 1px solid black;} </style></head>" echo "<title> REPORT </title>" echo... (0 Replies)
Discussion started by: archana25
0 Replies

2. Shell Programming and Scripting

Loop to convert text output in the HTML format

Hello Everyone, I have a sample file raw.txt as shown below : Drive Bays Bay Name : SD-2C Number of Standby Power Supplies : 4 Number of Drive Enclosures : 12 Summary Status of Contained Modules All... (6 Replies)
Discussion started by: rahul2662
6 Replies

3. Shell Programming and Scripting

Format text file to html

Hi Experts, Anybody out there figure out on how to achieve in shell scripts or tools. I have done googling to find solutions but no luck. I have thousands of .txt files to batch process, please see the below sample text content after -------- start here --------. What I want to achieve is to... (10 Replies)
Discussion started by: lxdorney
10 Replies

4. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

5. Shell Programming and Scripting

Convert data to a tabular format

How can i convert the below data to a simpler format :- cat tabular.txt User 1 Details :- First Name = Tom Middle Name = Last Name = Hanks Age = 40 Address = User 2 details :- First Name = Mike Middle Name = Last Name = Tyson Age = 50 Address = (2 Replies)
Discussion started by: lazydev
2 Replies

6. Shell Programming and Scripting

Need a unix script to convert date into Julian format in a text file

The 6th & 7th column of the text files represents date & time. I need this to be converted in julian format using command "date +%s -d <date>". I know the command, but dont know how to use it on the script 0 dbclstr-b IXT_Web Memphis_Prod_SQL_Full Memphis-Prod-SQL-Full-Application-Backup... (4 Replies)
Discussion started by: ajiwww
4 Replies

7. UNIX for Dummies Questions & Answers

How to convert a text file into tab delimited format?

I have a text file that made using text editor in Ubuntu. However the text file is not being recognized as space or tab delimited, the formatting seems to be messed up. How can I convert the text file into tab delimited format? (3 Replies)
Discussion started by: evelibertine
3 Replies

8. Programming

awk script to convert a text file into csv format

hi...... thanks for allowing me to start a discussion i am collecting usb usage details of all users and convert it into csv files so that i can export it into some database.. the input text file is as follows:- USB History Dump by nabiy (c)2008 (1) --- Kingston DataTraveler 130 USB... (2 Replies)
Discussion started by: certteam
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

Convert comma text file to Column in html format

I am trying to generate a report with below file : File1 : EQADM,edrtere9-phys,8122caef0,gpatmon,/bin/ksh,nuten Erick EQADM,edrtere11-phys,8227caef0,gpatmon,/bin/ksh,nuten Erick EQADM,edrtere3-phys,822caef0,gpatmon,/bin/ksh,nuten Erick can you help me convert it to html and add... (9 Replies)
Discussion started by: sriram003
9 Replies
Login or Register to Ask a Question