Why does the tr command not read from file

historytr

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?

Best Answer

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
Related Question