I looked up a Unix book, the man and the wikipedia page for tr
but could not find a reason why it was designed/implemented in such way that it does not read from file but strictly only from the standard input. For instance, tools such as wc
, grep
, sed
, and awk
all will happily read input from file if provided or from standard input. Was/Is there a compelling reason to design tr
this way?
Asked
Active
Viewed 4,984 times
13

Jeff Schaller
- 67,283
- 35
- 116
- 255

Ketan
- 9,226
1 Answers
16
The UNIX philosophy advocates for "small, sharp tools", so the answer is that reading from a file would be bloat contrary to the UNIX philosophy. As to why wc
, grep
, sed
, awk
, etc do read from files, the answer is that they all have features that require more than one input or input selection or otherwise require direct access to the files. As tr
is not commonly used for those reasons you are left with one of the following forms to meet your needs;
tr ... < file
tr ... < file > file2
tr ... < file | sponge file

user1133275
- 5,574
standard input < -
to gettr
to act on a file, e.g.tr "this text" "to this text" < some_file.txt
. – marshki Oct 26 '16 at 00:46tr
from Multics as a derivative of PL/1translate
built-in function, which in turn was a generalization of aTR
command in System/360 architecture (see IBM System-360 Green Card). Worth noting that QNX implementation could actually read from a file via-r
– don_crissti Nov 01 '16 at 00:33