mercredi 1 octobre 2014

How to create HTML table from CSV data, but when data is rotated in BASH?


Vote count:

0




I have a CSV table like this:



a1@b1@c1
a2@b2@c2
a3@b3@c3
a4@b4@c4
a5@b5@c5
a6@b6@c6
...



  • The CSV has 3 columns, but any number of rows.


I use this simple BASH script to create HTML tables from the data:



#!/bin/bash

echo "<table>" >> output.html

while read -r line
do
cella="$(awk -F@ '{ print $1 }' <<< "$line")"
cellb="$(awk -F@ '{ print $1 }' <<< "$line")"
cellc="$(awk -F@ '{ print $1 }' <<< "$line")"
echo "<tr><td>"$cella"</td><td>"$cellb"</td><td>"$cellc"</td></tr>" >> output.html
done < data.csv

echo "</table>" >> output.html


This creates an HTML table that displays like this:



a1 | b1 | c1
---|----|---
a2 | b2 | c2
---|----|---
a3 | b3 | c3
---|----|---
a4 | b4 | c4
---|----|---
...


I need to output an HTML table though where the data is presented like this:



a1 | a2 | a3 | a4 | ...
-------------------
b1 | b2 | b3 | b4 | ...
-------------------
c1 | c2 | c3 | c4 | ...


How can I use BASH to output the data from the CSV table in this rotated format?



asked 13 secs ago







How to create HTML table from CSV data, but when data is rotated in BASH?

Aucun commentaire:

Enregistrer un commentaire