- Learning Linux Shell Scripting
- Ganesh Naik
- 87字
- 2021-06-25 22:02:50
The tr command
The tr command is a Linux utility for text processing, such as translating, deleting, or squeezing repeated characters, which is shown as follows:
$ tr '[a-z]' '[A-Z]' < filename
This will translate the lowercase characters to uppercase:
$ tr '|' '~' < emp.lst
This will squeeze multiple spaces into a single space:
$ ls -l | tr -s " "
In this example, the -s option squeezes multiple contiguous occurrences of the character into a single char. Additionally, the -d option can remove characters.