Skip to content

Instantly share code, notes, and snippets.

@xbalaji
Last active October 10, 2022 05:06
Show Gist options
  • Save xbalaji/513f7300c12c0f8bc22522471922624a to your computer and use it in GitHub Desktop.
Save xbalaji/513f7300c12c0f8bc22522471922624a to your computer and use it in GitHub Desktop.
oneliners-convert-to-data-url.sh
# simple script to convert text file to data url
# html
convert2dataurl() {
gawk 'BEGIN {print "data:text/html,<html><head><style>p{ font-family: \"Courier New\" }</style></head><html><body><p>"} {printf "%s<br/>", $0} END {print "</body></html>"}' $1
}
convert2dataurl data.txt
# plain text
convert2dataurl2 data.txt
convert2dataurl2() {
echo data:text/plain\;base64,$(cat $1 | base64 -w0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment