>_ IzzyLab

Hands-on task

This task is step 12 of the course “Linux: everyday tasks”

Convert a file to uppercase

medium~7 min

The contents of /root/input.txt must be written to /root/upper.txt with all letters converted to uppercase — both plain Latin and accented ones (é, à). Leave everything else (spaces, line order) unchanged.

What you'll practise:
  • case conversion
  • sed \U
  • awk toupper
  • UTF-8 and multibyte characters
  • input/output redirection

Topic breakdown

tr (translate) does character-by-character substitution between sets of characters, but GNU tr actually works on bytes. With plain Latin letters you don't notice: in UTF-8 every ASCII letter is one byte. Accented letters such as é or à, however, take two bytes each, and tr leaves them alone — a common trap when processing logs and configs that contain names, addresses or text in other languages. Locale-aware tools — sed (\U in the replacement) and awk (toupper) — read the text as characters and change the case of any letter correctly, as long as the locale is UTF-8 (the LANG variable).

What's checked

  1. file /root/upper.txt created
  2. plain ASCII line in uppercase
  3. line with accented letters in uppercase
  4. line count unchanged

What it looks like