I have two csv files like this:
user size aaa 10 bbb 20 ccc 30
name value www 5 mmm 8 ppp 9
I want to convert this to two separate HTML tables using a shell script. How do I do this?
Assume the fields in your files separated by spaces and you've only two fields in every row:
sed -E '1 s@^([^ ]*) *(.*)@<table><tr><th>\1</th><th>\2</th></tr>@ ; \ 2,$ s@^^([^ ]*) *(.*)@<tr><td>\1</td><td>\2</td></tr>@ ; \ $ s,.*,&</table>,' test1.csv
The first line assumes the first line of
test1.csv is table head. Open the
<table> tag, a
<tr> and enclose every field between
<th>. After it closes the
</tr>. The second line is similar but only transforms from the second line of
The third line appends the last line (
</table> to close the
table tag (opened in first line).
You can do it with pure
awk of course.