home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


tr

tr [options ] [string1 [string2 ]]

Copy standard input to standard output, performing substitution of characters from string1 to string2 or deletion of characters in string1 . System V requires that string1 and string2 be enclosed in square brackets. BSD versions do not have this requirement.

Options

-c

Complement characters in string1 with characters in the current character set. The complement is the set of all characters not in string1 .

-d

Delete characters in string1 from output.

-s

Squeeze out repeated output characters in string2 .

Examples

Change uppercase to lowercase in a file:

tr '[A-Z]' '[a-z]' < file

Solaris allows the use of character classes:

tr '[:upper:]' '[:lower:]' < file

Turn spaces into newlines (ASCII code 012):

tr ' ' '\012' < file

Strip blank lines from file and save in new.file (or use \011 to change successive tabs into one tab):

tr -s "" "\012" < file > new.file

Delete colons from file ; save result in new.file :

tr -d : < file > new.file

Make long search path more readable:

echo $PATH | tr ':' '\n'


Previous: Reference: tput UNIX in a Nutshell: System V Edition Next: Reference: troff
Reference: tput Book Index Reference: troff

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System