- Linux Shell Scripting Cookbook(Third Edition)
- Clif Flynt Sarath Lakshman Shantanu Tushar
- 70字
- 2021-07-09 19:46:18
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:]'