mirror of
https://github.com/Hizenberg469/Makefile-tutorial.git
synced 2026-04-20 06:12:23 +03:00
grep added
This commit is contained in:
67
shell/grep.txt
Normal file
67
shell/grep.txt
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
Grep:
|
||||||
|
(Global regular expression print)
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
Purpose:
|
||||||
|
The purpose of grep is to search for text within file.
|
||||||
|
|
||||||
|
|
||||||
|
To use grep:
|
||||||
|
|
||||||
|
Print the content of the file using cat command and pipe it
|
||||||
|
to grep command.
|
||||||
|
|
||||||
|
cat <filename> | grep <string-pattern>
|
||||||
|
|
||||||
|
Pass the string pattern as an argument to search for it in the file.
|
||||||
|
|
||||||
|
* To search for anything except the <string-pattern>
|
||||||
|
|
||||||
|
cat <filename> | grep -v <string-pattern>
|
||||||
|
|
||||||
|
-v : excluding the <string-pattern> and searching everything else.
|
||||||
|
|
||||||
|
* To search using grep without using cat command.
|
||||||
|
|
||||||
|
Use command:
|
||||||
|
|
||||||
|
grep <string-pattern> <file-location>
|
||||||
|
|
||||||
|
This gives same output as it will show if we use it with cat command.
|
||||||
|
|
||||||
|
* To mention the line number for each <string-pattern> searched and found in the file.
|
||||||
|
|
||||||
|
Use command:
|
||||||
|
|
||||||
|
grep -n <string-pattern> <file-location>
|
||||||
|
|
||||||
|
* To get only the count of the occurences of the <string-pattern> in the <file>
|
||||||
|
|
||||||
|
Use command:
|
||||||
|
|
||||||
|
grep -c <string-pattern> <file-location>
|
||||||
|
|
||||||
|
|
||||||
|
NOTE:
|
||||||
|
|
||||||
|
Grep is case sensitive for the <string-pattern> we use for searching.
|
||||||
|
|
||||||
|
|
||||||
|
* To Ignore the case sensitivity.
|
||||||
|
|
||||||
|
Use command:
|
||||||
|
|
||||||
|
grep -i <string-pattern> <file-location>
|
||||||
|
|
||||||
|
* To look through every file in the given directory where grep is executed.
|
||||||
|
|
||||||
|
Use command:
|
||||||
|
|
||||||
|
grep <string-pattern> *
|
||||||
|
|
||||||
|
* To know where the particular pattern are present without knowing the particular file
|
||||||
|
and directory.
|
||||||
|
|
||||||
|
Use command:
|
||||||
|
|
||||||
|
grep -r <string-pattern> <path>
|
||||||
Reference in New Issue
Block a user