Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Created July 17, 2025 08:33
Show Gist options
  • Save masakielastic/6025cde117c2e85a7759c31b4bd40f2d to your computer and use it in GitHub Desktop.
Save masakielastic/6025cde117c2e85a7759c31b4bd40f2d to your computer and use it in GitHub Desktop.
コードポイントと文字の往復変換コマンドを作成する

コードポイントと文字の変換コマンドを作成する

chmod +x ord
chmod +x chr
> ord あ
3042 
> chr 3042
あ
> ord あいうえお
3042 3044 3046 3048 304A 
> chr 3042 3044 3046 3048 304A
あいうえお
input="$1"
echo -n "$input" \
| grep -oP . \
| while IFS= read -r char; do
printf '%X ' "'$char"
done
echo
for cp in "$@"; do
printf '%b' "\\U$(printf '%08X' 0x$cp)"
done
printf '\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment