3

How I can convert a string to UTF-8 encoding using Ubuntu terminal only?

1
  • Welcome to Ask Ubuntu! From what encoding are you trying to convert?
    – Melebius
    Nov 19, 2019 at 10:47

1 Answer 1

6

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

5
  • Thank you but I found many examples on file, not for some string that's why I opened this question 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
    – lese
    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 the echo command
    – damadam
    Nov 19, 2019 at 10:54
  • @damadam Whether ' or " should be used depends on the particular case. ' doesn’t allow any expansion and is perfectly valid here.
    – Melebius
    Nov 19, 2019 at 10:58
  • @damadam: Thank you for your feedback | Melebius: Ok I understand
    – lese
    Nov 19, 2019 at 10:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .