What is the 'tr' command?

QuestionsQuestions8 SkillsProSimple Text ProcessingOct, 18 2025
0102

The tr command in Linux is a utility used for translating, deleting, or squeezing characters from standard input and writing the result to standard output.

Basic Syntax:

tr [OPTION]... SET1 [SET2]
  • SET1: The set of characters to be translated or deleted.
  • SET2: The set of characters that will replace those in SET1 (used for translation).

Common Options:

  • -d: Delete characters in SET1.
  • -s: Squeeze repeated characters into a single occurrence.

Examples:

  1. Translate lowercase to uppercase:

    tr 'a-z' 'A-Z' < input.txt
  2. Delete specific characters:

    tr -d 'abc' < input.txt
  3. Squeeze repeated spaces:

    tr -s ' ' < input.txt

The tr command is useful for text processing tasks, such as cleaning up data or formatting text. If you need more specific examples or have questions about its usage, let me know!

0 Comments

no data
Be the first to share your comment!