TR(1B)
π TR(1B) β like, the BSD translate-characters moment β¨
okay bestie, gather round, because this one is a whole vibe. it's the BSD compatibility version of tr β translate characters β and yes, she lives at /ucb/tr, not just anywhere. the manual page calls herself TR(1B) and comes to you straight out of the BSD System Compatibility corner of the universe π¦
πΈ SYNOPSIS πΈ
/ucb/tr [-cCds] [string1 [string2]]
that's it. that's the whole entrance. two little strings, a handful of flags, and a dream π
β¨ DESCRIPTION β¨
so here's the tea, fr fr: tr copies standard input to standard output, but with substitution or deletion of selected characters along the way. glow-up included, no extra charge π
the input characters you find in string1 get mapped into the corresponding characters of string2. and when string2 is shorter than string1? she doesn't panic β she gets padded to the length of string1 by duplicating her last character. iconic behaviour, honestly π
any combination of the options -cds may be used:
-cβ complements the set of characters in string1 with respect to the universe of characters whose byte codes are01through0377octal, or, with a multibyte character set, whose wide character codes start at1. (yes, the complement era πͺ)-dβ deletes all input characters in string1. gone. not invited to the group chat π-sβ squeezes all strings of repeated output characters that are in string2 to single characters. one of each, she's not doing duplicates π
the following option has been introduced by POSIX.1-2001 (so she's, like, officially certified β¨):
-Cβ complements the set of characters in string1 like-cdoes, but orders ranges according to the collation sequence. same energy, different ordering energy π
in either string, these character sequences are treated specially β memorize these, they're the main characters:
\octalβ the character\followed by 1, 2 or 3 octal digits stands for the character whose byte code is given by those digits. multibyte characters can be specified as a sequence of octal bytes. (so like,\012is a whole thing, ok? π)\charβ the escape sequences\a(bell),\b(backspace),\f(form feed),\n(newline),\r(carriage return),\t(horizontal tabulator), and\v(vertical tabulator) are supported. a\followed by any other character (other than an octal digit) stands for that character. basically the backslash is a lil escape artist π§a-zβ means a range of characters from a to z in increasing byte order, or, with a multibyte character set, in increasing wide character order. with the-Coption, characters are ordered according to the collation sequence π[:class:]β means all characters that belong to character class class in the currentLC_CTYPElocale in increasing byte order, or, with a multibyte character set, in increasing wide character order. and here's the cute part: if both[:upper:]and[:lower:]appear at the same position in either string, upper-case characters are mapped to lower-case characters (and vice versa!). a literal swap, we love to see it π[=c=]β where c is a collating symbol in the currentLC_COLLATElocale, means all characters that belong to the same equivalence class as c, i. e. have the same collating weight as c. (same weight = same squad βοΈ)[a*n]β means n repetitions of the character a, with n as an octal number if it starts with0and as a decimal number otherwise. if a is omitted or zero, it is taken to be huge β super useful for padding string2 to the length of string1, like, the ultimate filler arc π«Ά
π¦ ENVIRONMENT VARIABLES π¦
LANG,LC_ALLβ seelocale(7). the classics πLC_COLLATEβ affects the composition of equivalence classes. (wellβ¦ see the NOTES, bestie, there's a plot twist π)LC_CTYPEβ determines the mapping of bytes to characters in translation strings and input files, and the availability and composition of character classes. she decides who's who and what's what π
π₯ EXAMPLES π₯
the following examples create a list of all the words in file1, one per line, in file2 β where a word is taken to be a maximal string of alphabetics. the second string is quoted to protect \ from the Shell. 012 is the ASCII code for newline. periodt.
/ucb/tr -cs A-Za-z Β΄\012Β΄ <file1 >file2
like, look at her go ππ
π SEE ALSO π
ed(1), ascii(7), locale(7) β go read those too, iykyk β¨
π NOTES π
okay important caveats, do not skip these: -trdoes not handle ASCII NUL in string1 or string2; it always deletes NUL from input. no cap, NUL is just not welcome here π - theLC_COLLATEvariable is not respected; equivalence classes consist of exactly one character, and the-cand-Coptions produce identical results. yeahβ¦ the collation thing is lowkey just for show in this version π«
and that's the whole page, bestie! this lil beauty comes to you from the Heirloom Toolchest, dated 8/6/05 β go forth and translate those characters, you absolute main character πππ
π¦ where this page comes from
- nixos 26.05: heirloom 070715
- nixpkgs unstable: heirloom 070715
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms