Saturday, August 1, 2009

Linux command : tr

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

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

Examples
Type the following command at shell prompt:
$ tr "h2" "3x" <>
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.



No comments:

Post a Comment