问题
How can I convert a CSV file into html table? I got a csv file with comma "," and I want this file to convert to Html table.
回答1:
OK, you really want it only in bash? Mission accomplished.
cat > input.csv
a,b,c
d,e,f
g,h,i
echo "<table>" ; while read INPUT ; do echo "<tr><td>${INPUT//,/</td><td>}</td></tr>" ; done < input.csv ; echo "</table>"
<table>
<tr><td>a</td><td>b</td><td>c</td></tr>
<tr><td>d</td><td>e</td><td>f</td></tr>
<tr><td>g</td><td>h</td><td>i</td></tr>
</table>
My first try used "cat" but I figured that was cheating, so I rewrote it using "while read"
回答2:
XmlGrid.net has a nice tool to convert a CSV file into HTML table. Here is the link: http://xmlgrid.net/csvToHtml.html
来源:https://stackoverflow.com/questions/5255449/convert-csv-to-html-table-using