Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

[SYNTAX] grep command

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

Go down

[SYNTAX] grep command Empty [SYNTAX] grep command

Post by Christopher 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
Christopher
Christopher
Admin

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

https://unixcpp.forumotion.com

Back to top Go down

Back to top


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

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