Change encoding of txt file
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"
Use iconv:
echo "$var" | iconv --from-code=utf-8 --to-code=utf-16le --output=file2.txt