Name
grep
Synopsis
grep [options
]regexp
[files
]
Search one or more files for lines that match a regular expression regexp. Regular expressions are described in Chapter 7. Exit status is 0 if any lines match, 1 if not, and 2 for errors. See also egrep and fgrep.
Options
The options for grep are the same as for egrep, including the Solaris versus GNU
differences. For Solaris, there is an exception: /usr/xpg4/bin/grep also accepts the
-q
option. See egrep for the full list.
Examples
List the number of users who use the C shell:
grep -c /bin/csh /etc/passwd
List header files that have at least one #include
directive:
grep -l '^#include' /usr/include/*
List files that don’t contain pattern :
grep -c pattern files
| grep :0
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.