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

Share:
7,033
Noman Maqsood
Author by

Noman Maqsood

having 6+ years of Software Engineering, Technology Enthusiast

Updated on September 18, 2022

Comments

  • Noman Maqsood
    Noman Maqsood over 1 year

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

    • Melebius
      Melebius over 4 years
      Welcome to Ask Ubuntu! From what encoding are you trying to convert?
  • Noman Maqsood
    Noman Maqsood over 4 years
    Thank you but I found many examples on file, not for some string that's why I opened this question
  • lese
    lese over 4 years
    ah ok updated, you can try but I honestly don't know if a simple string can contain the encoding information
  • damadam
    damadam over 4 years
    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
  • Melebius
    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
    lese over 4 years
    @damadam: Thank you for your feedback | Melebius: Ok I understand