find a file's encoding
See which character encoding a text file is in, and convert it to UTF-8.
Steps
-
file -i file.txtthe kind of file and its charset (macOS: file -I)
-
iconv -f ISO-8859-1 -t UTF-8 in.txt > out.txtconvert it to UTF-8
-
iconv -lthe encodings iconv knows
-
uchardet file.txta better guess, if uchardet is installed
Notes
- No tool can be sure of an encoding: it is a guess from the bytes.
Commands used
fileiconv
Each has a page in lore: lore file opens it.
Related recipes
- add up numbers in a fileSum a column of numbers, from a file or a command's output.
- compare two foldersFind which files differ between two folders, or are only in one of them.
- count lines of codeHow many lines of code a project has, in total and by language.
- count lines, words and filesCount the lines of a file or of a command's output, the words, and the files in a folder.