Convert string to UTF-8 with terminal only
7,033
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
Author by
Noman Maqsood
having 6+ years of Software Engineering, Technology Enthusiast
Updated on September 18, 2022Comments
-
Noman Maqsood over 1 year
How I can convert a string to UTF-8 encoding using Ubuntu terminal only?
-
Melebius over 4 yearsWelcome to Ask Ubuntu! From what encoding are you trying to convert?
-
-
Noman Maqsood over 4 yearsThank you but I found many examples on file, not for some string that's why I opened this question
-
lese over 4 yearsah ok updated, you can try but I honestly don't know if a simple string can contain the encoding information
-
damadam over 4 yearsyou 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 -
Melebius over 4 years@damadam Whether
'
or"
should be used depends on the particular case.'
doesn’t allow any expansion and is perfectly valid here. -
lese over 4 years@damadam: Thank you for your feedback | Melebius: Ok I understand