Monday, March 25, 2019


Translate (tr) Command: -
Q) How to suppress multiple spaces present inside the below content of file f1 ?
Hi Ram   you are     there
    You are      good     bad 
Ans - $ cat f1 | tr –s ‘<One Space> ‘<Enter – Key>
Output –
Hi Ram you are there
 You are good bad
Q) How to suppress multiple t letter into single t present inside the below content of file f2 ?
Hi Ram yttttt are goodtttt ttt
Tttyou are ttt good
Ans - $ cat f2 | tr –s ‘t’<Enter – Key>
Output –
Hi Ram yt are goodt t
Ttyou are t good
Q) How to convert a word ‘apple’ to ‘APPLE’ ?
Ans – echo ‘apple’ | tr [a-z] [A-Z]<Enter – Key>
Q) How to convert a word ‘SMITH’ to lower case ?
Ans - $ echo ‘SMITH’ | tr [A-Z] [a-z]<Enter – Key>
Q) I am a good boy – Input
Output should be –
I
am
a
good
boy
Ans - $ echo ‘I am a good boy’ | tr –s ‘<One Space> ‘ ‘\n’<Enter – Key>
Q) Input –
I
am
a
boy
Output – I am a boy
Ans – echo ‘i
am
a
boy’ | tr –s ‘\n’ ‘<One Space>’<Enter – Key>
Q) Find the 37th word of a space separated file f1 ?
Ans - $ cat f1 | tr –s ‘ ‘ ‘\n’ | sed –n ‘37p’<Enter – Key>

tee Command: -
Q) Which command will show the output in screen and also saves the output in a file ?
Ans – tee command
Example –
$ ls –lrt | tee f1<Enter – Key>
This Command will show the output of ls –lrt in the screen and saves the output in a file f1.
Q) How to create multiple files with same content ?
Ans - $ tee file1 file2 file3 file4 ….<Enter – Key>
Content
Ctrl+c
$

No comments:

Post a Comment

Interview Questions: - (UNIX - 0) UNIX: -   Q) How to get inode number of a file/directory? Ans – $ ls –i <File/Directory_Name...