Skip to Content
Mac OS X in a Nutshell
book

Mac OS X in a Nutshell

by Jason McIntosh, Chuck Toporek, Chris Stone
January 2003
Intermediate to advanced
832 pages
32h 40m
English
O'Reilly Media, Inc.
Content preview from Mac OS X in a Nutshell

Name

tr

Synopsis

tr [options] [string1 [string2]]

Translates characters—copies standard input to standard output, substituting characters from string1 to string2, or deleting characters in string1.

Options

-c

Complement characters in string1 with respect to ASCII 001-377.

-d

Delete characters in string1 from output.

-s

Squeeze out repeated output characters in string2.

Special characters

Include brackets ([ ]) where shown.

\a

^G (bell)

\b

^H (backspace)

\f

^L (form feed)

\n

^J (newline)

\r

^M (carriage return)

\t

^I (tab)

\v

^K (vertical tab)

\ nnn

Character with octal value nnn.

\\

Literal backslash.

char1-char2

All characters in the range char1 through char2. If char1 does not sort before char2, produce an error.

[ char1-char2 ]

Same as char1-char2 if both strings use this.

[ char*]

In string2, expand char to the length of string1.

[ char*number ]

Expand char to number occurrences. [x*4] expands to xxxx, for instance.

[:class:]

Expand to all characters in class, where class can be:

alnum

Letters and digits

alpha

Letters

blank

Whitespace

cntrl

Control characters

digit

Digits

graph

Printable characters except space

lower

Lowercase letters

print

Printable characters

punct

Punctuation

space

Whitespace (horizontal or vertical)

upper

Uppercase letters

xdigit

Hexadecimal digits

[= char =]

The class of characters in which char belongs.

Examples

Change uppercase to lowercase in a file:

                     cat file | tr '[A-Z]' '[a-z]'

Turn spaces into newlines (ASCII code 012):

                     tr ' ' '\012' < file

Strip ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mac OS X Internals: A Systems Approach

Mac OS X Internals: A Systems Approach

Amit Singh
C++ In a Nutshell

C++ In a Nutshell

Ray Lischner
Linux Shell Scripting Cookbook - Third Edition

Linux Shell Scripting Cookbook - Third Edition

Clif Flynt, Sarath Lakshman, Shantanu Tushar
Optimized C++

Optimized C++

Kurt Guntheroth

Publisher Resources

ISBN: 0596003706Supplemental ContentCatalog PageErrata