Thursday, March 22, 2012

UNIX TOOLS - commad grep utility find match content in files

Unix Tools and Programming

Finding matching pattern using grep utility

Syntax:
grep "word-to-find" {file-name}
 
Create text file as follows:

$vi emo-file
hello world!
cartoons are good
especially toon like tom (cat)
what
the number one song
12221
they love us
I too


After saving file, issue following command,
$ grep "too" demofile
cartoons are good
especially toon like tom (cat)
I too
grep will locate all lines for the "too" pattern and print all (matched) such line on-screen. grep prints too, as well as cartoons and toon; because grep treat "too" as expression. Expression by grep is read as the letter t followed by o and so on. So if this expression is found any where on line its printed. grep don't understand words.

No comments:

Post a Comment