Wednesday, April 2, 2014

Grep function in unix

The grep command is used to search text or searches the given file for
lines containing a match to the given strings or words. By default,
grep displays the matching lines. Use grep to search for lines of text that match
one or many regular expressions, and outputs only the matching lines.
grep is considered as one of the most useful commands on Unix and other
 Linux operating systems.

The name, "grep", derives from the command used to perform a similar operation,
 using the Unix/Linux text editor ed:
g/re/p

Grep command syntax

Destination folder $grep 'search object' *.*

The syntax is as follows:
grep 'word' filename
grep 'word' file1 file2 file3
grep 'string1 string2'  filename
cat otherfile | grep 'something'
command | grep 'something'
command option1 | grep 'data'
grep --color 'data' fileName

How do I use grep command to search a file?

Search /etc/passwd file for boo user, enter:
$ grep boo /etc/passwd

No comments:

Post a Comment