Question
I have a bunch of text files that I'd like to convert from any given charset to UTF-8 encoding. Are there any command line tools or Perl (or language of your choice) one liners I can use to do this en masse?
How-To
iconv does convert between many character encodings. So adding a little bash magic and we can write:
- cov.sh
- for file in *.txt; do
- iconv -f ascii -t utf-16 "$file" -o "${file%.txt}.utf16.txt"
- done
This will run iconv -f ascii -t utf-16 to every file ending in .txt, sending the recoded file to a file with the same name but ending in .utf16.txt instead of .txt.
It's not as if this would actually do anything to your files while translating ASCII to UTF-8 (because ASCII is a subset of UTF-8), but to answer your question about how to convert between encodings.
Supplement
* iconv 指令轉換文字檔編碼(Big5 轉 UTF8、UTF8 轉 Big5 )
沒有留言:
張貼留言