I am trying to convert a YAML file to an HTML tables, It involves multiple complex conditions, I know this can be done using a shell script, but I have some problems in the implementation process, so come to the community for help.
The YAML content format is as follows.
- soft1: V1.0.1: http://example.com/v1.0.1.zip V1.0.2: http://example.com/v1.0.2.zip V1.0.3: http://example.com/v1.0.3.zip - soft1_beta_ver: V1.0.1: http://example.com/v1.0.1.zip V1.0.2: http://example.com/v1.0.2.zip V1.0.3: http://example.com/v1.0.3.zip - soft1_alpha_ver: V1.0.1: http://example.com/v1.0.1.zip V1.0.2: http://example.com/v1.0.2.zip V1.0.3: http://example.com/v1.0.3.zip - soft2: V1.0.1: http://example.com/v1.0.1.zip V1.0.2: http://example.com/v1.0.2.zip V1.0.3: http://example.com/v1.0.3.zip - soft2_beta_ver: V1.0.1: http://example.com/v1.0.1.zip V1.0.2: http://example.com/v1.0.2.zip V1.0.3: http://example.com/v1.0.3.zip - soft2_alpha_ver: V1.0.1: http://example.com/v1.0.1.zip V1.0.2: http://example.com/v1.0.2.zip V1.0.3: http://example.com/v1.0.3.zip < Omit more... >
It records the historical version of multiple software, I need to convert it to HTML table code and output it to a file separately.
For example, output soft1
, soft1_beta_ver
, and soft1_alpha_ver
to the same file (file name uses soft1
), soft2 to another file.
The format of the HTML table that needs to be converted is as follows.
<table> <thead> <tr> <th>type</th> <th>ver</th> <th>link</th> </tr> </thead> <tbody> <tr> <td>soft1</td> <td>V1.0.1</td> <td>http://example.com/v1.0.1.zip</td> </tr> <tr> <td>soft1</td> <td>V1.0.2</td> <td>http://example.com/v1.0.2.zip</td> </tr> <tr> <td>soft1</td> <td>V1.0.3</td> <td>http://example.com/v1.0.3.zip</td> </tr> <tr> <td>soft1_beta_ver</td> <td>V1.0.1</td> <td>http://example.com/v1.0.1.zip</td> </tr> <tr> <td>soft1_beta_ver</td> <td>V1.0.2</td> <td>http://example.com/v1.0.2.zip</td> </tr> <tr> <td>soft1_beta_ver</td> <td>V1.0.3</td> <td>http://example.com/v1.0.3.zip</td> </tr> <tr> <td>soft1_alpha_ver</td> <td>V1.0.1</td> <td>http://example.com/v1.0.1.zip</td> </tr> <tr> <td>soft1_alpha_ver</td> <td>V1.0.2</td> <td>http://example.com/v1.0.2.zip</td> </tr> <tr> <td>soft1_alpha_ver</td> <td>V1.0.3</td> <td>http://example.com/v1.0.3.zip</td> </tr> </tbody> </table>
This is the shell script I am trying, I don't know how to split the output into multiple files, and how to get the variables of the software type.
#!/usr/bin/env bash cat << EOF <table> <thead> <tr> <th>type</th> <th>ver</th> <th>link</th> </tr> </thead> <tbody> EOF while IFS=": " read -r softver softlink do cat << EOF <tr> <td>$softver</td> <td></td> <td><a href="$softlink">download</a></td> </tr> EOF done cat << EOF </tbody> </table> EOF
Any help or suggestion on this would be greatly helpful and much appreciated.