0% found this document useful (0 votes)
240 views2 pages

GREP Command

grep is a command line utility used for searching plain text data for lines matching a regular expression. It was originally developed for Unix systems and is available on Unix-like systems. grep searches for a literal string or regular expression in one or more files and prints the matching lines. The name grep comes from the ed command g/re/p, which performs the same function of doing a global regular expression search and printing matches.

Uploaded by

Anonymous ey6J2b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
240 views2 pages

GREP Command

grep is a command line utility used for searching plain text data for lines matching a regular expression. It was originally developed for Unix systems and is available on Unix-like systems. grep searches for a literal string or regular expression in one or more files and prints the matching lines. The name grep comes from the ed command g/re/p, which performs the same function of doing a global regular expression search and printing matches.

Uploaded by

Anonymous ey6J2b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

grep "this" demo_file

2. searching for the string in a many files.


syntax:
eg.

grep "string" file_pattern

grep "this" demo_*

3. case insensitive search


syntax: grep -i "string" filename
eg.

grep -i "this" demo_file

4. full word search


example :

grep -iw "is" demo_file

5. display N lines after match


syntax : grep -A <N> "string" filename
eg. grep -A 3 -i "example" demo_text
6. display N lines before match
syntax : grep -B <N> "string" filename
example: grep -B 2 "single word" demo_text
7. display N lines around match
syntax: grep -C <N> "string" filename
example: grep -C 2 "example"demo_text

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

You might also like