Character classes

The tr command can use different character classes as sets. Here are the supported character classes:

  • alnum: Alphanumeric characters
  • alpha: Alphabetic characters
  • cntrl: Control (nonprinting) characters
  • digit: Numeric characters
  • graph: Graphic characters
  • lower: Lowercase alphabetic characters
  • print: Printable characters
  • punct: Punctuation characters
  • space: Whitespace characters
  • upper: Uppercase characters
  • xdigit: Hexadecimal characters

We can select the required classes, like this:

tr [:class:] [:class:]

Consider this example:

tr '[:lower:]' '[:upper:]'