Need help to convert Flat file to HTML


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to convert Flat file to HTML
# 1  
Old 12-19-2006
Need help to convert Flat file to HTML

Hello

I need help to convert flat file data to HTML Table format.
I am generating everyday Flat file and want to convert into HTML Table format.

The format of my file is:

version host Total YRS NO APPS PSD
10 Sun 30 2 4 6 7

and flat file is TAB delimentaed.

Please do help me
# 2  
Old 12-19-2006
Code:
awk -v border=5 -v width=10 -v bgcolor="black" -v fgcolor="red" '
BEGIN { printf("<table border=\"%d\" bordercolor=\"%s\" width=\"%d\" bgcolor=\"%s\n>",border,bgcolor,width,fgcolor) }
{       print "<tr>";
        for( i = 1 ; i <= NF ; ++i )
                print "<td> "$i" </td>"
        print "</tr>"
}
END {  print "</table>" } ' file


Last edited by anbu23; 12-20-2006 at 01:31 AM..
# 3  
Old 12-19-2006
Try this:

$ awk -f flat2html.awk yourFile > output.html

flat2html.awk
Code:
BEGIN {
    FS="\t"
    print "<table>\n"
    format="<tr>\n\t<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>\n</tr>\n"
}

{
    printf (format, $1, $2, $3, $4, $5, $6, $7)
}

END {
    print "</table>"
}

# 4  
Old 12-19-2006
Code:
<table>[manually echo]
<tr><td>[manually echo]version	[tab -> </td><td>]host	[tab -> </td><td>]Total	[tab -> </td><td>]YRS	[tab -> </td><td>]NO	[tab -> </td><td>]APPS	[tab -> </td><td>]PSD[\n -> </td></tr>]
<tr><td>[manually echo]10	[tab -> </td><td>]Sun	[tab -> </td><td>]30	[tab -> </td><td>]2	[tab -> </td><td>]4	[tab -> </td><td>]6	[tab -> </td><td>]7[\n -> </td></tr>]
</table>[manually echo]

use sed:
Code:
% sed s/WHAT/TO/g

or awk:
Code:
% awk '{gsub(/WHAT/,"TI",$0); print}'

so script will do:

manually place
<table> before parsing this file,
parse the file echo <tr><td> before each line, change TAB -> </td><td>, change \n -> </td></tr>.
after parsing the file echo </table>

done.
# 5  
Old 12-19-2006
pls can u tell me how to run this code
regards
dips
# 6  
Old 12-19-2006
anbu23 please can you tell me how to run this script, it is giving me error on 1 line.
# 7  
Old 12-19-2006
Quote:
Originally Posted by getdpg
anbu23 please can you tell me how to run this script, it is giving me error on 1 line.
Can you show the error?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert content of file to HTML

Hi I have file like this: jack black 104 daniel nick 75 lily harm 2 albert 5 and need to convert it into the html table like this: NO.......name....family..... id 1...........jack.....black.....104 2..........daniel....nick.......75 3..........albert.................5 i mean... (5 Replies)
Discussion started by: indeed_1
5 Replies

2. UNIX for Dummies Questions & Answers

Convert flat file to csv

Hi I have a file like this: a=1 b=2 c=3 a=4 b=2 d=3 a=3 c=4 How can I change this to csv format a,b,c,d 1,2,3,, 4,2,,3 3,,4,, Please use code tags next time for your code and data. Thanks (10 Replies)
Discussion started by: sandip_2014
10 Replies

3. 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

4. Shell Programming and Scripting

Script to convert CSV file to HTML

Hi, I have made a a script which creates a csv file as daily database report However i want to covert that csv file to html because csv file does not have a good visibilty. So it is possible to have such csv to html coversion script. Your prompt help much appreciated. Thanks in advance (4 Replies)
Discussion started by: sv0081493
4 Replies

5. 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

6. UNIX for Dummies Questions & Answers

convert csv to html file

Hi All, I am new to this forum,not sure where to post this query...so posted here Kindly need any of your help on the below ------------ I am using shell scripting and trying to convert a csv file to html file... example.csv --------------- Name Country Age Sex Andy India 25 ... (4 Replies)
Discussion started by: sumithra
4 Replies

7. Shell Programming and Scripting

Convert case on specified position of flat file

Please help Need a script which will do the following : Search on fixed width file , go to position (25,2) which means 25th and 26th position, Find if there are any char in lower case: For example 25,2 can be (9T) or (9w) or (Ww) or (wW)....The two positions can be numeric or alpha...no... (13 Replies)
Discussion started by: ssantoshss
13 Replies

8. Shell Programming and Scripting

how to convert a html file to an .xml one

Hii every one. I have lots of .html files like: <html> <title> </title> <head> </head> <body> <ul id="SummaryRatings">4 stars </ul> <ul id="summaryList"> <p><b> Aurhor</b> </p> <p>wsfwfrfrtgretryetyrtyty</p> </ul> ...... ....... </body> </html> (6 Replies)
Discussion started by: kheyali Mitra
6 Replies

9. Shell Programming and Scripting

Awk to convert a flat file to CSV file

Hi , I have a file with contents as below: Contract Cancellation Report UARCNCL LOS CODE DATE REAS TYPE AMOUNT AMOUNT LETTER BY ========= ======= ==== ==== ==== ========= ==== ==== 8174739 7641509 1S NONE CRCD 30-JUN-2008 NPAR N .00 .00 CCAN 8678696 8091709 1S NONE DDEB 30-JUN-2008... (14 Replies)
Discussion started by: rkumudha
14 Replies

10. UNIX for Dummies Questions & Answers

Flat File to HTML

Is there a Unix product or command that can convert a flat file to an hTML document? (2 Replies)
Discussion started by: randerson
2 Replies
Login or Register to Ask a Question