Linux/Unix tr examples


$ cat bands
Brian:Jones:1942:The Rolling Stones
George:Harrison:1943:The Beatles
John:Lennon:1940:The Beatles
Keith:Richards:1943:The Rolling Stones
Mick:Jagger:1943:The Rolling Stones
Paul:McCartney:1942:The Beatles
Ringo:Starr:1940:The Beatles
Ron:Wood:1947:The Rolling Stones


Replace colons with a space:

$ cat bands | tr : " "
Brian Jones 1942 The Rolling Stones
George Harrison 1943 The Beatles
John Lennon 1940 The Beatles
Keith Richards 1943 The Rolling Stones
Mick Jagger 1943 The Rolling Stones
Paul McCartney 1942 The Beatles
Ringo Starr 1940 The Beatles
Ron Wood 1947 The Rolling Stones


Translate all lowercase letters to uppercase:

$ cat bands | tr '[a-z]' '[A-Z]'
BRIAN:JONES:1942:THE ROLLING STONES
GEORGE:HARRISON:1943:THE BEATLES
JOHN:LENNON:1940:THE BEATLES
KEITH:RICHARDS:1943:THE ROLLING STONES
MICK:JAGGER:1943:THE ROLLING STONES
PAUL:MCCARTNEY:1942:THE BEATLES
RINGO:STARR:1940:THE BEATLES
RON:WOOD:1947:THE ROLLING STONES


Delete all numbers:

$ cat bands | tr -d '[0-9]'
Brian:Jones::The Rolling Stones
George:Harrison::The Beatles
John:Lennon::The Beatles
Keith:Richards::The Rolling Stones
Mick:Jagger::The Rolling Stones
Paul:McCartney::The Beatles
Ringo:Starr::The Beatles
Ron:Wood::The Rolling Stones

Replace multiple spaces with a single space:

$ echo "a b  c  d    e     f"
a b  c  d    e     f
$ echo "a b  c  d    e     f" | tr -s ' ' ' '
a b c d e f