Skip to content

tr

tr - translate or delete characters.

most often used together with other commands.
example, make string all caps:
echo "Code Vault" | tr [a-z] [A-Z]
the first set [a-z] is replaced by the second set [A-Z].

alternatively,
echo "Code Vault" | tr [:lower:] [:upper:]

alternatively,
tr [a-z] [A-Z] < some-file.txt

deletion (delete all lower-case characters):
echo "Code Vault" | tr -d [a-z]

squeeze (s) out duplicate characters (e.g. k):
cat some-file.txt | tr -s "k"

delete every alphabet character:
cat some-file.txt | tr -d [:alpha:]

replace one character with another:
cat some-file.txt | tr "$" "#"