tr [OPTION] SET1 [SET2]

replace

cat content | tr “[:lower:]” “[:upper:]”

-c

complements the set of characters in string.i.e., operations apply to characters not in the given set

echo "my ID is 73535" | tr -cd [:digit:]

Output:

73535

-d

delete characters in the first set from the output.

echo "Welcome To GeeksforGeeks" | tr -d 'w'

Output:

elcome To GeeksforGeeks

-s

replaces repeated characters listed in the set1 with single occurrence

echo "Welcome    To    GeeksforGeeks" | tr -s [:space:] ' '

Output:

Welcome To GeeksforGeeks

-t

first truncates set1 to the length of set2, then do replacement

echo 'the cellar is the safest place' | tr -t abcdefghijklmn 123

output

the 3ell1r is the s1fest pl13e

without -t, character in set1 that is after set2 will repeat the last character in set1

t33 33331r 3s t33 s133st p3133


Published

07 April 2019

Category

operation

Tags