0

I modified a UTF-8 encoded xml file using vi editor and saved it.

I'm on Redhat Linux 7.9

I checked the file encoding after the changes and found it to be us-ascii

file --mime-encoding tmpfiles/08/config/jdbc/jdbc.xml
tmpfiles/08/config/jdbc/jdbc.xml: us-ascii

I decided to change the encoding back to UTF-8 using the below command:

iconv -f us-ascii -t UTF-8 tmpfiles/08/config/jdbc/jdbc.xml >tmpfiles/08/config/jdbc/jdbc.xmlenc

echo $?
0

However, the encoding for the new file jdbc.xmlenc did not change to UTF-8 and remained unchanged. See the output below:

file --mime-encoding tmpfiles/08/config/jdbc/jdbc.xmlenc
tmpfiles/08/config/jdbc/jdbc.xmlenc: us-ascii

Can you please suggest how can i change the file encoding to UTF-8?

1 Answer 1

5

It's going to be UTF-8 only if your document contains UTF-8 characters.

US-ASCII is a subset of UTF-8 thus any US-ASCII text is also a valid UTF-8 text. There's no need to convert anything.

4
  • Is there a way i can get UTF-8 printed as output? Commented Mar 29, 2022 at 13:17
  • I'm not sure I understand your question. Please clarify. Commented Mar 29, 2022 at 15:57
  • Is there any command that can print the superset i.e UTF-8 as output? Commented Mar 29, 2022 at 16:01
  • Would be great if you let us know what you're trying to achieve. Pure ASCII will be ASCII/UTF-8 no matter how you print it. Add any UTF-8 symbol and it will stop being ASCII and will become UTF-8. Commented Mar 29, 2022 at 16:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.