Red Hat Linux 9 Professional Secrets [Electronic resources]

Naba Barkakati

نسخه متنی -صفحه : 341/ 268
نمايش فراداده

tr

Purpose

Copies from standard input to standard output, while substituting one set of characters with another.

Syntax

tr [options]

string1

[

string2

]

Options

-c complements characters in

string1 with ASCII codes 001–377.

-d deletes from the input all characters specified in

string1.

-s replaces repeated sequences of any character in

string1 with a single character.

Description

The

tr command substitutes all characters in

string1 in the input with the corresponding characters in

string2 . For example, to convert the file

sample.lc to all uppercase and store in

sample.uc , type the following:

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

sample.lc >

sample.uc

To replace repeated occurrences of newlines in a file with a single newline character, type the following:

tr -s ‘\n’ <

infile >

outfile