help with a bash script to create a html table

Hi guys as the title says i need a little help i have partisally written a bash script to create a table in html

so if i use ./test 3,3

i get the following output

for the third arguement in the script i wish to include content that will be replace the A characters in the table this will be in the form of a text file as below

these would appear in table for as above can any one please give me a heads up as to how i can accomplish this ? Cheers guys

A point to start from (?):

#! /bin/bash

ROWS=3
COLS=3

LIST=(
  [11]="Apples"  [12]="Oranges" [13]="Bananas"
  [21]="Pears"   [22]="Kiwis"   [23]="Plums"
  [31]="Peaches" [32]="Grapes"  [33]="Melons"
)

echo "<table>"
for ((RI=1; RI<=$ROWS; RI++))
do
  echo -e "\t<tr>"
  for ((CI=1; CI<=$COLS; CI++))
  do
    echo -e "\t\t<td>${LIST[$RI$CI]}</td>"
  done
  echo -e "\t</tr>"
done
echo "</table>"

exit 0
[house@leonov] bash test.bash
<table>
        <tr>
                <td>Apples</td>
                <td>Oranges</td>
                <td>Bananas</td>
        </tr>
        <tr>
                <td>Pears</td>
                <td>Kiwis</td>
                <td>Plums</td>
        </tr>
        <tr>
                <td>Peaches</td>
                <td>Grapes</td>
                <td>Melons</td>
        </tr>
</table>

(Reference: Arrays)

{
  echo "<table>"
  printf "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n" $(cat "$file")
  echo "</table>"
}  > table.html
1 Like