tr:
Translates characters, but, generally, is used to substitute or delete
characters from the content of standard input.
Forms:
tr [-Ccsu] string1 string2
tr [-Ccu] -d string1
tr [-Ccu] -s string1
tr [-Ccu] -ds string1 string2
Options:
-C # Complement characters in string1. Everything except for the listed
characters.
$ echo "0123456789" | tr -C 13579 "[:number:]" " "
-c # Same as -C but complement the set of values in string1.
-d # Delete characters in string1 from the input.
-s # Squeeze multiple occurrences of the characters listed in the last
operand
(either string1 or string2) in the input into a single instance of
the character.
This occurs after all deletion and translation is completed.
-u # Guarantee that any output is unbuffered.
Escape Chars:
\char # A backslash followed by special characters escapes it to have
special meaning.
\a # Alert
\b # Backspace
\f # Form Feed
\n # Newline
\r # Carriage Return
\t # Tab>
\v # Vertical Tab
Examples:
tr -cs "[:alpha:]" "\n" < file1
$ echo "Round\t the\brugged" | tr -cs "[:alpha:]" "\n"
Round
the
rugged
# Create a list of the words in file1, one per line, where a word is
# taken to be a maximal string of letters.
tr "[:lower:]" "[:upper:]" < file1
# Translate the contents of file1 to upper-case.
tr a-z A-Z
$ echo "hello world" | tr a-z A-Z
HELLO WORLD
# A less locale-portable, but very common way to translate lowercase to
upper case.
tr -cd "[:print:]" < file1
# Strip out non-printable characters from file1.
tr "[=e=]" "e"
# Remove diacritical marks from all accented variants of the letter `e'Version
1, updated 135 days ago.
. o 0 (
edit |
history )