GREP Command
GREP stands for Globally search a regular expression and print
1.Search a string and print from a log/text file
Ex- grep “this” abc.text
Above command will search for “this” string in abc.text and it will print the corresponding line to the console.
2. Case insensitive search
grep -I “this” abc.tx
Above command will search for “this/THIS” string in abc.text and it will print the corresponding line to
the console.
3. Regular expression:
Grep “line.*empty” abc.*
Above command will search for “line. Some text which ends with empty” string in all the file named as abc and
it will print the corresponding line to the console.
Will search for strings like: line.abcempty, line.notempty etc.
4.Full word search :
Grep -w “sum” abc.text
Above command will search for complete word “sum” in abc.text and it will print the corresponding line to the
console.
5. Full word search with regular expression:
Grep -w “sum” *.log
Above command will search for complete word “sum” in all the log files and it will print the corresponding line
to the console.