- If you want an easy command-line based utility
to treat text, you might like tr.
What is tr about?
Well, tr stands for translate,
and it allows you to translate sets of characters
into other sets of characters.
And it is useful for converting uppercase into lowercase,
or the other way around,
or a completely different set of characters.
You typically use it in a pipe.
So, "echo hello", send it to a pipe.
Then you do your tr stuff,
by using either [:lower:] or [:upper:],
or [a-Z] [A-Z], or even [a-m] [n-z].
Let me demonstrate.
So I'm using echo hello | tr,
followed by [:lower:] and [:upper:].
And that is translating the text that to receive
from the pipe to uppercase.
The structure of using [:lower:] and [:upper:],
which basically is a regular expression,
is really a nice structure
because it works with many languages,
including languages that have special characters
that exist in languages like French, or German, or Spanish,
like accents, and so, below or above,
or around the character, and so on.
So, let's get started with echo hello |.
And |, that's to tr,
and then I'm using [a-z] [A-Z].
There we go.
This is translating "hello" into uppercase.
Now that's all nice, but this [a-z] [A-Z] doesn't work
unless it is a special accent,
which occurs in many languages
like Swedish, and German, and Spanish, and so on.
If you are working with words in these languages,
you might be better off using [:lower:] and [:upper:].
[:lower:] and [:upper:] is doing exactly the same
as [a-z] and uppercase [A-Z],
but it will deal the right way
with letters that are containing accents.
You can even do funny things with [A-Z].
What do you think of this one for instance?
[a-m] followed by [n-z]
is translating "hello" into "uryyo".
Everything up from A up to M
is translated in a matching character from N up to Z,
and that's how you can use the tr utility.
And in case you are wondering, why is that useful?
Well, this is something that is useful in scripts,
or any other environment where you need to make sure
that your words have a certain case.
Then, tr is a useful utility.