What is the function of the '[:lower:]' and '[:upper:]' character classes in the 'tr' command?

QuestionsQuestions8 SkillsProSimple Text ProcessingAug, 02 2025
0148

The [:lower:] and [:upper:] character classes in the tr command are used to represent all lowercase and uppercase letters, respectively.

  • [:lower:]: This character class matches all lowercase letters (a to z).
  • [:upper:]: This character class matches all uppercase letters (A to Z).

When used in the tr command, they allow you to easily convert text between these two cases. For example:

echo 'hello labex' | tr '[:lower:]' '[:upper:]'

This command converts all lowercase letters in the input string to uppercase, resulting in HELLO LABEX.

0 Comments

no data
Be the first to share your comment!