Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I write :

file file1.txt 

I have this output : Little-endian UTF-16 Unicode text, with CR line terminators

Then if I write :

file file2.txt 

I have : ASCII text

file2.txt is created by making :

echo $var > "file2.txt"

I would like file2.txt have the same encoding than file1.txt. How can I do that ?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

You can use iconv to convert the encoding of the file:

iconv -f ascii -t utf16 file2.txt > another.txt

another.txt should then have the desired encoding.

You could also try this:

echo $var | iconv -f ascii -t utf16 > "file2.txt"
share|improve this answer

Use iconv:

echo "$var" | iconv --from-code=utf-8 --to-code=utf-16le --output=file2.txt
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.