Skip to content

Instantly share code, notes, and snippets.

@lebensterben
Created June 18, 2019 00:59
Show Gist options
  • Save lebensterben/a6fab5c94e61d6ca67d9bdc0d149c504 to your computer and use it in GitHub Desktop.
Save lebensterben/a6fab5c94e61d6ca67d9bdc0d149c504 to your computer and use it in GitHub Desktop.
#-*- mode: shell-script -*-
# Get Unicode Representation of Given String(s)
#2utf() {
if [[ $# -eq 0 ]]; then
cat << EOF
Usage: to_unicode String [...]
Print the unicode representation of one or multiple strings.
At least one argument should be given, and if multiple arguments are given, they should be seperated by whitespaces.
Examples:
☠ -> '\xE2\x98\xa0'
吼 -> '\xe5\x90\xbc'
asdf -> '\x61\x73\x64\x66'
EOF
else
for i in $@; do
echo -n $i | od -An -tx1 | sed 's/\([0-9a-f]\)\{2\}/\\x&/g' | tr -d ' '
done
unset i
fi
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment