[SYNTAX] grep command

Unix C++ :: UNIX CPP :: UNIX :: SYNTAX

Go down

[SYNTAX] grep command

Post by Christopher on Sun Mar 14, 2010 4:53 pm

The grep command searches files or standard input globally for lines matching a given regular expression, and prints them to the program's standard output.

Syntax
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]

Simple Example
Code:
$ cat 1.txt
hi u der
make hi files wonderful
things computer windows
hi make ubuntu files
recover delete hi things
computer
computerjee
Hi Computer working!!!

$ grep 'computer' 1.txt
things computer windows
computer
computerjee

Case-insensitive Search (-i)
-i option is used to ignore case in search.

Code:
$ grep -i 'computer' 1.txt
things computer windows
computer
computerjee
Hi Computer working!!!

Multiple Pattern (-e)
-e option is used to search for multiple patterns in a file.

Code:
$ grep -e 'hi' -e 'computer' 1.txt
hi u der
make hi files wonderful
things computer windows
hi make ubuntu files
recover delete hi things
computer
computerjee

Complete Word Search (-w)
Select only those lines containing matches that form whole words.

Code:
$ grep -w 'hi' 1.txt
hi u der
make hi files wonderful
hi make ubuntu files
recover delete hi things
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Back to top

- Similar topics

Unix C++ :: UNIX CPP :: UNIX :: SYNTAX

 
Permissions in this forum:
You cannot reply to topics in this forum