Linux Shell Scripting Tutorial (LSST) v1.05r3
Prev
Chapter 5: Essential Utilities for Power User
Next

Translateing range of characters using tr utility

Type the following command at shell prompt:
$ tr "h2" "3x" < sname
11   Vivek
1x   Renuka
13   Prakas3
14   As3is3
15   Rani

You can clearly see that each occurrence of character 'h' is replace with '3' and '2' with 'x'. tr utility translate specific characters into other specific characters or range of characters into other ranges.
h -> 3
2 -> x

Consider following example: (after executing command type text in lower case)
$ tr "[a-z]" "[A-Z]"
hi i am Vivek
HI I AM VIVEK
what a magic
WHAT A MAGIC

{Press CTRL + C to terminate.}

Here tr translate range of characters (i.e. small a to z) into other (i.e. to Capital A to Z) ranges.

General Syntax & use of tr utility:
Syntax:
tr {pattern-1} {pattern-2}

Use of tr utility:
To translate range of characters into other range of characters.

After typing following paragraph, I came to know my mistake that entire paragraph must be in lowercase characters, how to correct this mistake? (Hint - Use tr utility)

$ cat > lcommunity.txt
THIS IS SAMPLE PARAGRAPH
WRITTEN FOR LINUX COMMUNITY,
BY VIVEK G GITE (WHO ELSE?)
OKAY THAT IS OLD STORY.


Prev
Home
Next
The join utility
Up
Data manipulation using awk utility