Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

encoding - How to pass any file to utf-8 in bash

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...