tr command & tips

Hi folks, Here I am with some nice nix commands tips/tricks
For this session, I have “tr” command……

tr command
The tr utility translates one set of characters into another. This utility copies the given input to produced the output with substitution or deletion of selected characters. tr abbreviated as translate or transliterate.

The tr command performs three kinds of operations
a) Transforming Characters
b) Deleting Characters Using the -d Flag
c) Removing Sequences Using the -s Flag

a) Transforming Characters

$echo “She is miss universe”  | tr ‘[a-z]’ ‘[A-Z]’
SHE IS MISS UNIVERSE


$echo “She is miss universe”  | tr ‘es’ ‘#@’
Sh# i@ mi@@ univ#r@#


Explanation :: the tr command replaces each character contained in String1 from the standard input with the character in the same position in String2.

b) Deleting Characters Using the -d Flag

echo “Shhee iiis misss universeee” | tr -d ‘s’
Shhee iii mi univereee


Explanation :: the tr command deletes each character contained in String1 from standard input.


c) Removing Sequences Using the -s Flag 
$echo “Shhee iiis misss universeee” | tr -s ‘s’
Shhee iiis mis universeee


$echo “Shhee iiis misss universeee” | tr -s ‘si’
Shhee is mis universeee



Explanation :: the tr command removes all but the first character in any sequence of a character string represented in String1

 
 

njoy the simplicity…….
©Victimizeit

Advertisements

About victimizeit
This is Atul.. working for IBM as a DataStage Developer. I may not be an expert on any particular DataStgae technology, but I'm sure I do know a few things about DB2, AIX, Unix, Windows, and DataBase. In this blog, I'll give out some tips on these subjects. If you find them useful, great, I'll be happy. Thanks for stopping by !!

What is your opinion ?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: