csv2html() {
IFS=,
echo "
"
echo ""
read -r speaker text
htmlrow "$speaker" "$text" th
echo ""
echo ""
while read -r speaker text; do
htmlrow "$speaker" "$text"
done
echo ""
echo "
"
}
htmlrow() {
cell=${3:-td}
printf "<%s>%s%s><%s>%s%s>
\n" \
"$cell" "$(escape_html "$1")" "$cell" \
"$cell" "$(escape_html "$2")" "$cell"
}
escape_html() {
str=${1//\&/&}
str=${str//<}
str=${str//>/>}
echo "$str"
}
html=$(
csv2html <<-END
Character,Speech
The multitude,The messiah! Show us the messiah!
Brians mother,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!
The multitude,Who are you?
Brians mother,I'm his mother; that's who!
The multitude,Behold his mother! Behold his mother!
END
)
echo "$html"