The grep command is very useful for search for strings and words in a file from the command line interface.
In windows we can use findstr to search for strings and words in the command prompt.
GREP
Usage: grep [OPTION]… PATTERN [FILE]
- -o searches for only the string
- -v searches for all words except the string .It is an inverted search
- -c counts the number of matching words for the string
grep “shepherd” filetosearch.txt
grep -o “He restoreth” filetosearch.txt
grep -v “want” filetosearch.txt
grep -c “” filetosearch.txt
We can also use grep for some system adminstration task
- top | grep firefox searches for firefox process in top
- netstat | grep tcp searches for firefox process in top
- ps -ef | grep firefox searches for firefox process
- df -h | grep sda*searches for all drives beginning with sda process in top
FINDSTR in windows
findstr short for findstring works like grep in linux and it is used to search or find strings
- tasklist | findstr firefox