tr

Linux · Text · available in the simulator

What it does

Translate or delete characters.

Syntax

tr [opciones] conjunto1 [conjunto2]

Options and parameters

  • -d

    Delete characters in the specified set.

    tr -d '\r' < archivo.txt
  • -s

    Replace each sequence of repeated characters with a single occurrence.

    tr -s ' '
  • -c

    Use the complement of the specified set.

Usage examples

  • echo hola | tr a-z A-Z
  • echo 'a b c' | tr -d ' '
  • tr -s ' ' < archivo.txt
  • tr -d '\r' < archivo
  • tr -d '\r' < archivo.txt
  • tr -s ' '

Notes and common mistakes

  • Only reads from standard input; used with pipes or redirections.
  • Typical example: echo hola | tr a-z A-Z
Practise tr

Related commands