How I can convert a string to UTF-8 encoding using Ubuntu terminal only?
1 Answer
iconv
should do what you are looking for
eg.:
echo 'latin string' | iconv -t utf-8 > yourfileInUTF8
Edit:
As suggested by damadam I removed the -f
option since the string typed in terminal uses the default encoding
-f, --from-code=NAME encoding of original text
-
Thank you but I found many examples on file, not for some string that's why I opened this question Commented Nov 19, 2019 at 10:31
-
ah ok updated, you can try but I honestly don't know if a simple string can contain the encoding information– leseCommented Nov 19, 2019 at 10:47
-
you can remove the
-f
option if OP wants to type the string from terminal, it takes the default encoding; also, I think it's better to use double quote"
for theecho
command– damadamCommented Nov 19, 2019 at 10:54 -
1@damadam Whether
'
or"
should be used depends on the particular case.'
doesn’t allow any expansion and is perfectly valid here.– MelebiusCommented Nov 19, 2019 at 10:58