Thursday, February 28, 2019

UNIX COMMAND

1.Display all letters in the sentence in capital.
[bgc@localhost ~]$ echo "i am a student" | tr " [ a-z ] " " [ A-Z ]"
I AM A STUDENT
[bgc@localhost ~]$

2. Display all letters in the sentence in small letter.

[bgc@localhost ~]$ echo "i am a student" | tr " [ A-Z ] " " [ a-z ]"
i am a student
[bgc@localhost ~]$

3. Replace all the spaces in a sentence with new line.

[bgc@localhost ~]$ echo "i am a student" | tr " " "\n"
i
am
a
student
[bgc@localhost ~]$

4.print all the word of a file in a line by line.

[bgc@localhost ~]$ cat > f20.txt
today is tuesday
i am a student
bhairab ganguly college
[bgc@localhost ~]$ cat f20.txt | tr " " "\n"
today
is
tuesday
i
am
a
student
bhairab
ganguly
college
[bgc@localhost ~]$

5. Replace all the ‘a’ in a file f20.txt with new line.

[bgc@localhost ~]$ cat f20.txt | tr "a" "\n"
tod
y is tuesd
y
i
m
student
bh
ir
b g
nguly college
[bgc@localhost ~]$

6.squeeze all spaces.

[bgc@localhost ~]$ echo "i am a          student" | tr -s " "
i am a student
[bgc@localhost ~]$

7. Squeeze all excess ‘a’ in a line.

[bgc@localhost ~]$ echo "aaaaa bbbbb a aaaaaa" | tr -s "a"
a bbbbb a a
[bgc@localhost ~]$

8. Squeeze all excess ‘a’ & ‘b’ in a line.

[bgc@localhost ~]$ echo "aaaaa bbbbb a aaaaaa" | tr -s "a" | tr -s "b"
a b a a
[bgc@localhost ~]$

9. Squeeze all excess ‘a’ , ‘b’ & ‘c’ in a line.

[bgc@localhost ~]$ echo "aaaaa bbbbb ccccc" | tr -s "a" | tr -s "b" | tr -s "c"
a b c
[bgc@localhost ~]$

10. Display only the 1st character in string.

[bgc@localhost ~]$ echo "abcdef" | cut -c1
a
[bgc@localhost ~]$

11. Display only the 3rd character in string.

[bgc@localhost ~]$ echo "abcdef" | cut -c3
c
[bgc@localhost ~]$

12. Display only the 5th character in string.

[bgc@localhost ~]$ echo "abcdef" | cut -c5
e
[bgc@localhost ~]$

13. Display the 1st, 3rd, 5th & 6th characters in string.

[bgc@localhost ~]$ echo "bhairab ganguly college" | cut -c 1,3,5,6
bara
[bgc@localhost ~]$

14. Display the 1st to 3rd, 5th to 9th & 11th characters in string.

[bgc@localhost ~]$ echo "bhairab ganguly college" | cut -c 1-3,5-9,11
bharab gn

[bgc@localhost ~]$

No comments:

Post a Comment