I have a file in us-ascii format that I want to pass to UTF-8. I am trying to use the following code where hola.psv is my original file and hola1.psv is the new file in utf-8 format:
# getting encoding format
encoding=`file -i hola.psv | sed 's/=/ /g' |awk '{print $4}'`
# from original format to utf-8
# if file is already in utf-8 format then no tranformation is needed
if [ ! $encoding == "utf-8" ]; then
iconv -f $encoding -t UTF-8//TRANSLIT hola.psv -o hola1.psv
else
echo "Document is already in utf-8 format"
fi
However when I do a double check to see if my new file is in utf-8 format, I'm still getting the us-ascii format.
question from:
https://stackoverflow.com/questions/65930025/how-to-pass-any-file-to-utf-8-in-bash 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…