Last active
January 27, 2023 18:35
-
-
Save yzorg/e4e9813fc07bef4af10ae43febca38d9 to your computer and use it in GitHub Desktop.
find all UTF-16 files and convert to UTF-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# see https://gist.github.com/yzorg/e4e9813fc07bef4af10ae43febca38d9 | |
# function to convert file to UTF-8 | |
convert_to_utf8() { | |
iconv -f UTF-16 -t UTF-8 "$1" -o "$1".utf8 | |
mv "$1".utf8 "$1" | |
} | |
# output the list before making the 1st change | |
find . -type f -exec file {} \; | grep "UTF-16" | |
# find all files in subdirectories and convert them to UTF-8 if they are in Unicode-16 format | |
find . -type f -exec file {} \; | grep "UTF-16" | awk '{print $1}' | | |
while read file; do | |
convert_to_utf8 "${file:0:-1}" | |
done |
- the ai generated version didn't handle ":" at the end of $1
file
output, so changed from$file
to${file:0:-1}
- it also doesn't handle spaces in directory names (known issue)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
initial commit is 100% ChatGPT