>_ IzzyLab

Hands-on task

This task is step 6 of the course “Encodings and checksums”

iconv: change the encoding

easy~3 min

The file /root/in.txt contains the text café in UTF-8 (the letter é takes 2 bytes). Convert it to ISO-8859-1 (latin1) into the file /root/out.txt, where é takes one byte.

What you'll practise:
  • iconv
  • -f
  • -t
  • encodings
  • UTF-8
  • ISO-8859-1

Topic breakdown

The same characters are represented by different bytes in different encodings: in UTF-8 "é" is two bytes (0xC3 0xA9), in the single-byte ISO-8859-1 it is one (0xE9). iconv -f SOURCE -t TARGET converts a stream between character sets. iconv -l lists the supported encodings. If a character can't be represented in the target encoding, iconv fails by default — the //TRANSLIT suffix substitutes a similar character, //IGNORE drops untranslatable ones. Conversion is needed when working with old files, databases and legacy systems that aren't UTF-8.

What's checked

  1. file got shorter
  2. é encoded as 0xE9

What it looks like