TRS(1)
π¦ trs π¦
okay bestie, welcome to TRS(1), straight out of the Linux User's Manual π
this one's a little filter with main character energy and honestly? she ate.
β¨ NAME β¨
trs β filter replacing strings. that's it, that's the whole vibe π
πΈ SYNOPSIS πΈ
trs [-[r]e] 'REPLACE_THIS WITH_THAT [AND_THIS WITH_THAT]...'
trs [-[r]f] FILE
π DESCRIPTION π
So what she does is: copy stdin to stdout, and replace every occurrence of the given strings with other ones. She's giving tr(1) energy but β¨ upgraded β¨ β because she replaces whole strings, not just single chars. no cap.
Rules are separated by whitespace, and you can either hand them over directly after the -e option, or let her read them from FILE. And here's the cute part β if an argument isn't preceded by -e or -f, she guesses: if it contains some whitespace she treats it like a script, otherwise she treats it like a filename. lowkey psychic of her π§
Comments are allowed from # until the end of the line. but heads up β a literal # inside a string has to be written as \#. periodt.
Standard C-like escapes are recognized, all of them, no crumbs left:
\a \b \e \f \n \r \t \v \\ \nnn
And in addition (bonus slay), \s means a space character, and \! means an empty string. π«
Sets of acceptable characters at a given position can be specified between \[ and ]. ASCII ranges inside sets can be written short as FIRST-LAST. And when a set consists of only a single range, you can just skip the \[ and ] entirely. efficiency icon π«Ά
When a part of the string to translate is enclosed in \{...\}, only that part gets replaced. Any text outside \{...\} serves as an assertion: a string is translated only if it's preceded by the given text and followed by another one. And \{ at the beginning or \} at the end of the string can be omitted. Text outside \{...\} is treated as untranslated, okurrr.
Before the beginning of the file and after its end there are only \n's. So, for example, \n\{.\}\n matches . on a line by itself β including the first line, and the last one even without the \n marker. the way she handles edge cases ππ
A fragment of the form \?x=N, where x is a letter A-Za-z and N is a digit 0-9, contained in the target text sets the variable x to the value N when that rule succeeds. A similar fragment in the source text causes the given rule to be considered only if that variable has such value. Initially all variables have the value of 0. Several assignments or conditions can be present in one rule β and they're ANDed together. math girlie behavior π₯
π OPTIONS π
-eβ give the translation rules directly in the command line.-fβ get them from the file specified.-rβ reverse every rule. this affects only the next-eor-foption. and of course, it doesn't have to give the reverse translation! any rule containing any of\{\}\[\]\{\}\-is taken in only one direction. you may force any rule to be taken in only one direction by enclosing the string to translate in\{...\}. π--helpβ display help and exit.--versionβ output version information and exit.
Multiple -e or -f options are allowed. All rules are loaded together then, and earlier ones have precedence. first come, first served, iykyk π
π EXAMPLE π
$ echo Leeloo |trs -e 'el n e i i aqq o\}\n x o u'
Linux
not her turning Leeloo into Linux π iconic
π DIFFERENCES FROM sed π
The main difference between trs and sed 's///g; ...' (excluding sed's regular expressions) is that sed takes every rule in the order specified and applies it to the whole line of translated file, whereas trs examines every position and tries all rules in this place first. In sed every next rule is fed with the text produced by the previous one, whereas in trs every piece of text can be translated at most once (if more than one rule matches at a given position, the one mentioned earlier wins). That's why sed isn't well suited for translating between character sets. On the other hand, tr translates only single bytes, so it can't be used for Unicode conversions, or TeX / SGML ways for specifying extended characters. so basically: pick your fighter π₯
Another example, because she loves to flex:
$ echo 642 |trs -e '4 7 72 66 64 4'
42
$ echo 642 |sed 's/4/7/g; s/72/66/g; s/64/4/g'
666
β οΈ bestie listen: the string to replace can be empty β but then there must be something outside\{\}. In this special case only one such create-from-nothing rule can succeed at a given position. For example,\}\x80\-\xFF @precedes every character with high byte set with@. And heads up β the rule of the formsome\{ thingdoesn't work at the end of a file. π
π SEE ALSO π
π COPYRIGHT π
trs is a filter replacing strings. It forms part of the konwert package.
Copyright (c) 1998 Marcin 'Qrczak' Kowalczyk
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
β AUTHOR β
__("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.home.ml.org/
\__/ GCS/M d- s+:-- a21 C+++>+++$ UL++>++++$ P+++ L++>++++$ E->++
^^ W++ N+++ o? K? w(---) O? M- V? PS-- PE++ Y? PGP->+ t
QRCZAK 5? X- R tv-- b+>++ DI D- G+ e>++++ h! r--%>++ y-
and that's the whole page, bestie π this one's Konwert, dated 12 Jul 1998, and you just read TRS(1). slay, go translate something cute π¦β¨
π¦ where this page comes from
- debian bookworm: konwert 1.8-13.2
- debian trixie: konwert 1.8-15 Β· GPL-2.0-or-later
- ubuntu jammy: konwert 1.8-13.2
- ubuntu noble: konwert 1.8-13.2
- ubuntu questing: konwert 1.8-15
- ubuntu resolute: konwert 1.8-15build1 Β· GPL-2.0-or-later
- ubuntu stonking: konwert 1.8-15build1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms