How to convert multiple ISO8859-1 to UTF-8
Solution 1
iconv
defaults to sending its output to stdout, which explains the behaviour of what you saw. You can direct the output to a file using the -o
option, but that will only generate a single output file, and probably won't help you update the files in place. Perhaps try something like this:
for file in *.sql; do
iconv -f ISO-8859-1 -t UTF-8 -o "$file".utf "$file" && mv "$file".utf "$file"
done
That will convert each file and store the result in a temporary file, moving it to the original file name if the conversion was successful.
Solution 2
It is also possible to use rsync to this task, with one advantage, you will keep a backup. If one of the converted files is already in the target codification you will mess it up.
rsync -va --iconv=iso88591,utf8 /source/latin1/ /destination/utf8/
Related videos on Youtube
Luis Alvarado
System Engineer Social Engineer Master in Pedagogy Master in Open Source CCNA Certified Linux Foundation Certified Former Askubuntu Moderator Stack Careers | Linkedin | Launchpad | Ubuntu Wiki - Random SE Stuff - Latin American Members | JC Race Award | Human Robot Award 74
Updated on September 18, 2022Comments
-
Luis Alvarado over 1 year
Am trying to convert several SQL files from ISO8859-1 to UTF-8
Am doing the following command:
iconv -f ISO_8859-1 -t UTF-8 *.sql
What i get is an output of their content to the terminal which is very long and after ending the output they do not convert. They stay the same. I wish to be able to convert and not see the output.
-
Luis Alvarado about 13 yearsThat is some smart script there James. Thank you very much.
-
SergioAraujo almost 9 yearsIt is also possible to use rsync to this task, with one advantage, you will keep a backup. If one of the converted files is already in the target codification you will mess it up.
rsync -va --iconv=utf8,iso88591 /source/latin1/ /destination/utf8
-
James Henstridge almost 9 years@user3798: sounds like a good solution. Why not leave it as an answer so people can vote for it?