Make quick changes to files with tr – translate
The tr command can save you a lot of time and for quick changes and may be easier than using sed or awk.
While the Stream Editor (sed) and awk programming language can be powerful tools with the ability to interpret and act on regular expressions, tr can perform some of their find and replace functionality in an easy to implement format.
We’ll use a small text file to see how tr can be useful.
This is a quote from Abraham Lincoln’s Gettysburg Address:
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that, that nation might live. It is altogether fitting and proper that we should do this.
Copy that excerpt into a .txt file using your favorite text editor or using the echo command. The echo option is shown below.