Skip to content

Instantly share code, notes, and snippets.

@marios88
Last active July 4, 2020 06:50
Show Gist options
  • Save marios88/08edab7091b0c48cdc59c70ac62fb4b3 to your computer and use it in GitHub Desktop.
Save marios88/08edab7091b0c48cdc59c70ac62fb4b3 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Find the current encoding of the file
# place in $HOME/bin
# to mass use it
# find "$PWD" -type f -name "*" -exec recodeifneeded utf-8 {} \;
encoding=$(uchardet "$2")
if [[ "$1" != "${encoding}" ]] && [[ "${encoding}" != "UTF-8" ]] && [[ "${encoding}" != "unknown" ]]
then
# Encodings differ, we have to encode
echo "recoding from ${encoding} to $1 file : $2"
recode ${encoding}..$1 $2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment