Short way to escape HTML in Bash?
Escaping HTML really just involves replacing three characters: <
, >
, and &
. For extra points, you can also replace "
and '
. So, it's not a long sed
script:
sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g'
You can use recode
utility:
echo 'He said: "Not sure that - 2<1"' | recode ascii..html
Output:
He said: "Not sure that - 2<1"