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 of data which would demand a dinamic number of rows for each file.

In example, for

project XYZ
filename filecode size remotecode remote filesize
abcd 1234 5248 5678 3567

I would have many files, each in a new row. Do you have a suggestion how to make it work? I have two ideas: one is to reformat the existing text file, other is to make a new filter which would add html tags on the fly.

Thanks for any help.

Just a quick example, you can elaborate from here :rolleyes:

# ls
file1   file2

# cat file1
project XYZ
filename filecode size remotecode remote filesize
abcd 1234 5248 5678 3567

# cat file2
project abg
filename filecode size remotecode remote filesize
abcd 4321 4321 4321 3567

# awk 'BEGIN{print "<html><table>"}{sub("^","<tr><td>");sub("$","<\/td><\/tr>");$1=$1}1 END{print "<\/table><\/html>"}' OFS="<\/td><td>" file*
<html><table>
<tr><td>project</td><td>XYZ</td></tr>
<tr><td>filename</td><td>filecode</td><td>size</td><td>remotecode</td><td>remote</td><td>filesize</td></tr>
<tr><td>abcd</td><td>1234</td><td>5248</td><td>5678</td><td>3567</td></tr>
<tr><td>project</td><td>abg</td></tr>
<tr><td>filename</td><td>filecode</td><td>size</td><td>remotecode</td><td>remote</td><td>filesize</td></tr>
<tr><td>abcd</td><td>4321</td><td>4321</td><td>4321</td><td>3567</td></tr>
</table></html>

Thanks, danmero. I started thinking in that direction, but there's a header with some information which should be positioned in the first couple of rows. So, if I tried to create the table in suggested way, it wouldn't quite work. OK, I think I'll try adding special characters in front of the lines which are different and process them with conditions. Thanks for the help, once again. Other ideas are welcome as well.