Skip to content
Sign upLog in
← Back to Community

Unix S41 : command with clear examples

Profile icon
sasivanga

Session-41. tr command with clear examples

**tr means translate : **
This command translate character by character

tr 'sa' 'SA' < test.txt
empno,enAme,SAl
101,ShAShi,2000
102,SAi,3000
103,lASyA,9000
104,ShivA,8000

2)lLower case alphabets with uppercase

2)tr [a-z] [A-Z] < test.txt
EMPNO,ENAME,SAL
101,SHASHI,2000
102,SAI,3000
103,LASYA,9000
104,SHIVA,8500
105,MANI,900
109,ZEVA,000

Upper with lower and lower with upper

3)tr ‘[a-z] [A-Z]’ ‘[A-Z][a-z]’ < test.txt

Replace with 7 all aeiou

4)tr 'aeiou' '7' < test.txt
5)tr ‘,’ ‘\t’ <test.txt

tr ‘,’ ‘:’ <test.txt
empno:ename:sal
101:shashi:2000
102:sai:3000
103:lasya:9000
104:shiva:8500
105:Mani:900

  1. delete specific character a all occurrences

tr -d ‘a’ <test.txt
empno,enme,sl
101,shshi,2000
102,si,3000
103,lsy,9000
104,shiv,8500
105,Mni,900
109,zev,000

  1. tr -d ‘aeiou’ < test.txt
    It will delete all lowercase vowels in test.txt

  2. tr -s 'a' < test.txt
    -s means squeeze repeats
    Any sequence of a’s will be replaced with single a

Voters
Profile icon
FaraFalade
Profile icon
Highwayman
Profile icon
sasivanga