Translates characters (BSD version).
The trbsd command deletes or substitutes characters from standard input and then writes the result to standard output. The trbsd command is the BSD version of the tr command. The trbsd command performs three kinds of operations, depending on the character strings specified by the parameters and flags specified. The default value for either the String1 or String2 parameter is a null string.
Transforming Characters
If both the String1 and String2 parameters are specified and the -d flag is not specified, the trbsd command replaces each character from standard input that is specified by the String1 parameter with the character in the same position in the String2 parameter.
If the String1 parameter specifies a character more than once, the character is translated into the character in the String2 parameter that corresponds to the last occurrence of the character in the String1 parameter.
Deleting Characters Using the -d Flag
If the -d flag is specified, the trbsd command deletes each character from standard input that is specified by the String1 parameter.
Removing Sequences of Characters Using the -s Flag
If the -s flag is specified, the trbsd command deletes from standard input all but the first character in a sequence of two or more repetitions of any character specified by the String2 parameter.
Both the String1 and String2 parameters must be specified when both the -d and -s flags are specified.
Note: The trbsd command deletes all null characters from standard input before it begins processing.
Special Sequences for Expressing Strings
The strings contained in String1 and String2 parameters can be expressed using the following conventions:
Item | Description |
---|---|
C1-C2 | Specifies the string of characters that collate between the character specified by the C1 string and the character specified by the C2 string, inclusive. The character specified by the C1 string must collate before the character specified by the C2 string. |
\Octal | Specifies the character whose encoding is represented by the specified octal value. The octal value can be a one-, two-, or three-digit octal integer. Multibyte characters can be expressed by writing backslash-octal sequences for each byte. |
\- | The \- (backslash, minus sign) specifies the minus sign character itself, without any special meaning as an escape character. |
If the strings specified by the String1 and String2 parameters are not the same length, the trbsd command pads the shorter string to equal the length of the longer string. Padding is accomplished by duplicating the last character in the shorter string as many times as necessary.
Item | Description |
---|---|
-A | Performs all operations on a byte-by-byte basis using the ASCII collation order for ranges and character classes, instead of the collation order of the current locale. |
-c | Specifies that the value of the String1 parameter be replaced by the complement of that string. The complement is all of the characters in the character set of the current locale, except for the characters specified by the String1 parameter. If the -A and -c flags are specified together, characters are complemented with respect to the set of all 8-bit character codes. |
-d | Deletes each character from standard input that is contained in the String1 parameter. |
-s | Deletes from standard input all but the first character in a sequence of two or more repetitions of any character contained in the String2 parameter. |
trbsd '{}' '()' < textfile > newfile
This
translates each { (left brace) to ( (left parenthesis)
and each } (right brace) to ) (right parenthesis).
All other characters remain unchanged.trbsd '+\-/*' '\-+*/' < textfile > newfile
The
minus sign must be entered with a backslash escape character.trbsd 'a-z' 'A-Z' < textfile > newfile
trbsd -cs 'a-zA-Z' '\012' < textfile > newfile
This
translates each sequence of characters other than lowercase letters
and uppercase letters into a single newline character. The octal value
012 is the code for the newline character. trbsd -s '\012' < textfile > newfile
Item | Description |
---|---|
/usr/bin/trbsd | Contains the trbsd command. |
/usr/ucb/tr | Contains a symbolic link to the trbsd command. |