ODOC: tr

tr – Translate or Delete characters

Summary :

tr will Translate, squeeze, and/or delete characters from stdin, writing to stdout.

Examples :

$ echo “fslog” | tr “fs” “FS” — Translate f to F & s to S.

$ echo “fslog” | tr “[a-z]” “[A-Z]” — Change case (lower to upper)

$ echo “HelloooOOOoooo” | tr -s ‘[:lower:]’ — Squeez the “lower” case letters.

$ echo “FxSyLzoyg” | tr -d xyz — Remove xyz

$ cat myfile | tr -s ‘n’ — Remove repeated new lines.

$ echo “ABCDEFG” | tr -c “ACEG” “n” — Expect “ACEG” translate others to newline char.

‘tr’ supports few std esc sequences, regular expressions, char classes
(lower, upper, space, blank, alpha,…), etc.

Read : man tr

Tech Tags: linux