Bash 5 reference · Text and System Tools
tr (Linux command)
Translate, squeeze or delete characters, such as changing case, removing carriage returns or splitting words onto lines.
Bash 5
Syntax
tr [-d] [-s] SET1 [SET2]
Parameters
| Parameter | Description |
|---|---|
'a-z' 'A-Z' |
Map one set to another. |
-d '\r' |
Delete characters. |
-s ' ' |
Squeeze repeated characters. |
Examples
echo 'make me loud' | tr a-z A-Z
echo 'too many spaces' | tr -s ' '
Output
MAKE ME LOUD too many spaces
Run this on your computer — see “Get Started” for setup.
echo 'one two three' | tr ' ' '\n'
printf 'line\r\n' | tr -d '\r' | od -c | head -1
Output
one two three 0000000 l i n e \n
Run this on your computer — see “Get Started” for setup.
Related
sed· Edit text streams: substitute with s/old/new/, delete or print lines by number or pattern, and edit files in place.cut· Extract columns from each line by delimiter and field number, or by character positions.- Bash sort, uniq, cut and tr · tutorial