The command tr stands for translate. And, indeed, you can use tr for a variety of translation chores. No, not from one language to another, but rather, from one character to another, from a range of characters to another, or from one class of characters to another. You can also delete selected characters from a file, or eliminate duplicate characters.
The tr utility can’t use arguments, so you’ll either have to use a stdin redirector, or pipe its input from another command. In this example, the IP Addresses are enclosed within double quotes to maintain the space delimiter. This is piped to tr which translates the space between the IP Addresses to a new line “\n”. So tr is translating one character, in this example empty space, to another character, in this case a new line.
echo “192.168.7.26 192.168.3.34 192.168.4.2″ | tr ” ” “\n”
192.168.7.26
192.168.3.34
192.168.4.2
After the “tr”, is placed two text strings in single quotes. The first string represents what you want to find and change. The second string represents what you want to change the first string to.


Comments on this entry are closed.