filmov
tv
Using grep command to search string in files and folders - ~3Minutes: Tutorial
Показать описание
Using grep command to search string in files and folders - ~3Minutes: Tutorial
grep command
## Command Usage:
grep [options] ["search pattern"[regex]] [filename/foldername]
Note: use double quotes for your search string
Options : (Below are frequently used options with grep command)
-i Ignores case
-n Print the line number
-c Count of matched pattern (Will not print the search line, rather it just prints the count)
-r Will search folders for matching text.
-v non-matched lines are printed
----------------------------------------
### Example:
1) Lets search for "cat"
grep "cat" filename
2) Lets search for "tiger" and "cat" with line number inside folder
grep "tiger\|cat" -nr
3) Lets search in folder(s) for file content not having "Dog" in the line also ignore case sensitivity
grep -ivr "dog" foldername
**Try for yourself:**
1) Search for any string and print count
hint: use -c
2) Search entire folder for match pattern with , (This is special symbol)
hint: "\,"
3) Search string by ignoring the case and also search for multiple string in a file
hint: use -v and in search string you need to split using \| for multiple search string.
----------------------------------------
grep command
## Command Usage:
grep [options] ["search pattern"[regex]] [filename/foldername]
Note: use double quotes for your search string
Options : (Below are frequently used options with grep command)
-i Ignores case
-n Print the line number
-c Count of matched pattern (Will not print the search line, rather it just prints the count)
-r Will search folders for matching text.
-v non-matched lines are printed
----------------------------------------
### Example:
1) Lets search for "cat"
grep "cat" filename
2) Lets search for "tiger" and "cat" with line number inside folder
grep "tiger\|cat" -nr
3) Lets search in folder(s) for file content not having "Dog" in the line also ignore case sensitivity
grep -ivr "dog" foldername
**Try for yourself:**
1) Search for any string and print count
hint: use -c
2) Search entire folder for match pattern with , (This is special symbol)
hint: "\,"
3) Search string by ignoring the case and also search for multiple string in a file
hint: use -v and in search string you need to split using \| for multiple search string.
----------------------------------------
Комментарии