GREP Command
GREP Command
grep is a command line utility for searching plain text data set or lines matching a
regular expression. grep was originally developed for the unix operating system, but
is available for all unix like systems. its name comes from the ed command
g/re/p(globally search a regular expression and print), which has the same effect:
doing a global search with the regular expression and printing all matching lines.
Syntax:
grep "literal_string' filename
1. search for the string in a single file.
syntax : grep "literal_string" filename
eg.
8. recursively searching
example: grep -r "student" *
9. invert searching
example : grep -v "go" filename
10. counting the number of matches
syntax: grep -c "pattern" filename
example : grep -c "go" demo_text
11. display only the file names which matches the give pattern
example: grep -l this demo_*
12. show the position of match in the line
syntax: grep -o -b "pattern" filename
example: -o -b "3" filename
o=match only string
b= show position
13. show line number while displaying the output.
syntax: grep -n 'go" filename