Uname Command: -
Q) How you know the operating system details in Unix ?
Ans - $ uname –a<Enter – Key>
Q) How you know the operating system name in unix ?
Ans - $ uname<Enter – Key>
Q) How you know the version number of unix operating system
?
Ans - $ uname –v<Enter – key>
Q) How you know the number of bytes of unix operating system
?
Ans - $ uname –i<Enter – Key>
Grep Command: - (Global Search for Regular Expression and
Print it)
Q) Why we need grep command ?
Ans – Grep command is used to search a pattern from a file
and print it.
Example –
$ cat FileSample.txt
For Single pattern (bad): -
$ grep bad FileSample.txt<Enter – Key>
You will get all lines that have ‘bad’ pattern.
For Multiple Patterns (i am): -
Q) How you calculate the total number of lines ‘bad’ pattern
is present in the above file FileSample.txt ?
Ans - $ grep –c bad FileSample.txt<Enter –
Key>
Q) How you find the number of line in which bad pattern is
present, the line containing bad word in the above file FileSample.txt ?
Ans - $ grep –n bad FileSample.txt<Enter –
Key>
Q) How to get the rows in which bad pattern is not present
in above file FileSample.txt ?
Ans - $ grep –v bad FileSample.txt<Enter – Key>
V -> Verbose Mode
Q) How to get the rows in which only bad pattern is present
in the above file FileSample.txt ?
Ans - $ grep –w bad FileSample.txt<Enter – Key>
Q) How to find the rows in which bad pattern is present in
capital letter like Bad, BAD, baD,bAd etc or bad pattern ?
Ans - $ grep –I bad FileSample.txt<Enter – Key>
I -> insensitivity
In this command, you will get bad pattern rows in which bad
pattern present in capital letters or bad pattern.
Q) How to know if a particular pattern is present in the
file or not ?
Ans - $ grep –l <Pattern> <File Name><Enter –
Key>
If this command returns file name, then this
pattern is present in the file otherwise not present.
Q) How to know if a particular pattern is not present in the
file ?
Ans - $ grep –L <Pattern> <File Name><Enter –
Key>
If this command returns file name, then this pattern is not
present in the file otherwise present.
Q) How to find the rows in which ‘I am’ pattern is present
in beginning of the line in the above file FileSample.txt ?
Ans - $ grep ‘^I am’ FileSample.txt<Enter – Key>
Q) How to find the rows in which boy pattern is present in
end of the line in the above file
FileSample.txt ?
Ans - $ grep ‘boy$’ FileSample.txt<Enter –
Key>
Q) How to get rows in which pattern present along with subsequent
below 2 lines in which also same pattern present ?
Ans - $ grep –m <Number of times + 1> <Pattern>
<File Name><Enter – Key>
Q) How to get only pattern from a file ?
Ans - $ grep –o <Pattern> <File Name><Enter –
Key>












No comments:
Post a Comment