From an awk script I want to generate a HTML file. My string could include characters like "<" and "&". Is there a short and proven function for awk which does the escaping?
To escape the bare minimum you can do:
function escapeHtml(t)
{
# Must do this one first
gsub(/&/, "\\&", t);
gsub(/"/, "\\"", t)
gsub(/</, "\\<", t);
gsub(/>/, "\\>", t);
return t;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With