The tr command

translate or delete characters 6 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.

Options in the examples

-d, --delete
delete characters in ARRAY1, do not translate
-s, --squeeze-repeats
replace each sequence of a repeated character that is listed in the last specified ARRAY, with a single occurrence of that character

Examples

echo 'hello' | tr 'a-z' 'A-Z'

Lowercase to uppercase

echo 'Hello World' | tr ' ' '_'

Replace spaces with _

echo 'hello' | tr -d 'l'

Delete all 'l' chars

cat file.txt | tr -s ' '

Squeeze multiple spaces

cut -d, -f1 data.csv | tr 'a-z' 'A-Z'
df / | awk 'NR == 2 {print $5}' | tr -d %

8: just the number

Lessons that use tr

Related commands