Converting a text file to HTML

Hi,
I need to convert a text file formatted like this ("tshark -z conv,ip" output) to HTML:

=====================================================================================================
IPv4 Conversations
Filter:<No Filter>
                                               |       <-      | |       ->      | |     Total     |
                                               | Frames  Bytes | | Frames  Bytes | | Frames  Bytes |
192.168.1.246      <-> 192.168.1.135            2       276       1        60       3       336
192.168.1.255      <-> 192.168.1.167            2       184       0         0       2       184
192.168.1.255      <-> 192.168.1.99             1       265       0         0       1       265
192.168.1.255      <-> 192.168.1.164            1       126       0         0       1       126
10.0.0.255      <-> 10.0.0.250            1       126       0         0       1       126
192.168.1.255      <-> 192.168.1.41             1        92       0         0       1        92
=====================================================================================================

Preferably the rows and the columns would be in a table so the data is nicely aligned. Are there any tools that would allow me to do this from a script? ...or do I need to use sed/awk? If so, how?

Thank you! :smiley:

Let me be more specific. I can display the data I need by doing:

awk '//{print $1,$3,$5,$7,$9}' file.txt |grep -v "|" |grep -v "Filter" |grep -v "IPv4" |grep -v "="

Now I would like to add the following HTML tags:

<TR><TD> in front of $1
</TD><TD> in front of $2, $3, $5, $7, $9
</TD></TR> at the end of each line (after $9)

How would I go about doing that?

Thank you! :smiley:

Here's what I did and it actually works. It's very inefficient though:

awk '//{print $1,$3,$5,$7,$9}' file.txt |grep -v "|" |grep -v "Filter" |grep -v "=" |grep -v "IPv4" |sed 's/^/<TR><TD>/' |sed 's" "</TD><TD>"' |sed 's" "</TD><TD>"' |sed 's" "</TD><TD>"'|sed 's" "</TD><TD>"' |sed 's"$"</TD></TR>"g' >file.htm

Can you guys help me shorten it?

Grazie! :smiley:

This should work:

awk -v a="<TR><TD" -v b="</TD><TD>" -v c="</TD></TR>" 'BEGIN{print "<html><table>"}/^[0-9]/{print  a$1b$3b$5b$7b$9c}END{print "</table></html>"}' file.txt > file.htm

Sweet!
Thank you! :smiley: