Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I have a Medical.csv file with rows of following format,

    field: 'participation.type', displayName: 'program_type', type: 'String',path:'participation'
    field: 'participation.program', displayName: 'program_name', type: 'String',path:'participation'

I want to write a bash script to convert it to HTML table with field, displayName and type as headers dynamically.

The Csv2HtmlConverter.sh (Inspired by answer at Convert csv to html table usingConvert csv to html table using) is

    echo "<table>" ;
    while read INPUT ; do
            echo "<tr><td>${INPUT//,/</td><td>}</td></tr>" ;
    done < Medical.csv ;
    echo "</table>"

The result for above script is as below which is fine to some extent but I want to add <th>field</th>, <th>displayName</th> dynamically.

<table>
<tr><td>field: 'participation.type'</td><td> displayName: 'program_type'</td><td> type: 'String'</td><td>path:'participation'</td></tr>
<tr><td>field: 'participation.program'</td><td> displayName: 'program_name'</td><td> type: 'String'</td><td>path:'participation'</td></tr>
</table>

I have a Medical.csv file with rows of following format,

    field: 'participation.type', displayName: 'program_type', type: 'String',path:'participation'
    field: 'participation.program', displayName: 'program_name', type: 'String',path:'participation'

I want to write a bash script to convert it to HTML table with field, displayName and type as headers dynamically.

The Csv2HtmlConverter.sh (Inspired by answer at Convert csv to html table using) is

    echo "<table>" ;
    while read INPUT ; do
            echo "<tr><td>${INPUT//,/</td><td>}</td></tr>" ;
    done < Medical.csv ;
    echo "</table>"

The result for above script is as below which is fine to some extent but I want to add <th>field</th>, <th>displayName</th> dynamically.

<table>
<tr><td>field: 'participation.type'</td><td> displayName: 'program_type'</td><td> type: 'String'</td><td>path:'participation'</td></tr>
<tr><td>field: 'participation.program'</td><td> displayName: 'program_name'</td><td> type: 'String'</td><td>path:'participation'</td></tr>
</table>

I have a Medical.csv file with rows of following format,

    field: 'participation.type', displayName: 'program_type', type: 'String',path:'participation'
    field: 'participation.program', displayName: 'program_name', type: 'String',path:'participation'

I want to write a bash script to convert it to HTML table with field, displayName and type as headers dynamically.

The Csv2HtmlConverter.sh (Inspired by answer at Convert csv to html table using) is

    echo "<table>" ;
    while read INPUT ; do
            echo "<tr><td>${INPUT//,/</td><td>}</td></tr>" ;
    done < Medical.csv ;
    echo "</table>"

The result for above script is as below which is fine to some extent but I want to add <th>field</th>, <th>displayName</th> dynamically.

<table>
<tr><td>field: 'participation.type'</td><td> displayName: 'program_type'</td><td> type: 'String'</td><td>path:'participation'</td></tr>
<tr><td>field: 'participation.program'</td><td> displayName: 'program_name'</td><td> type: 'String'</td><td>path:'participation'</td></tr>
</table>
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k
Source Link
prayagupadhyay
  • 5.1k
  • 12
  • 35
  • 38

Convert csv to HTML table

I have a Medical.csv file with rows of following format,

    field: 'participation.type', displayName: 'program_type', type: 'String',path:'participation'
    field: 'participation.program', displayName: 'program_name', type: 'String',path:'participation'

I want to write a bash script to convert it to HTML table with field, displayName and type as headers dynamically.

The Csv2HtmlConverter.sh (Inspired by answer at Convert csv to html table using) is

    echo "<table>" ;
    while read INPUT ; do
            echo "<tr><td>${INPUT//,/</td><td>}</td></tr>" ;
    done < Medical.csv ;
    echo "</table>"

The result for above script is as below which is fine to some extent but I want to add <th>field</th>, <th>displayName</th> dynamically.

<table>
<tr><td>field: 'participation.type'</td><td> displayName: 'program_type'</td><td> type: 'String'</td><td>path:'participation'</td></tr>
<tr><td>field: 'participation.program'</td><td> displayName: 'program_name'</td><td> type: 'String'</td><td>path:'participation'</td></tr>
</table>