Content added Content deleted
imported>mutante m (Replacing page with '<jargon />') |
imported>mutante mNo edit summary |
||
Line 1: | Line 1: | ||
The grep command searches one or more input files for lines containing a match to a specified pattern. |
|||
* http://www.gnu.org/software/grep/ |
|||
How can I list just the names of matching files? |
|||
:'''<tt>grep -l 'main' *.c</tt>''' |
|||
How do I search directories recursively? |
|||
:'''<tt>grep -r 'hello' /home/gigi</tt>''' |
|||
Suppose I want to search for a whole word, not a part of a word? |
|||
:'''<tt>grep -w 'hello' *</tt>''' |
|||
How do I output context around the matching lines? |
|||
:'''<tt>grep -C 2 'hello' *</tt>''' |
|||
How can I search in both standard input and in files? |
|||
:'''<tt>Use the special file name `-':</tt>''' |
|||
:'''<tt>cat /etc/passwd | grep 'alain' - /etc/motd</tt>''' |
|||
more on |
|||
* |
|||
http://www.gnu.org/software/grep/doc/grep.html |
|||
try |
|||
'''<tt>$ cat FILENAME|grep SUCHWORT1|grep UND_SUCHWORT2|grep -v OHNE_SUCHWORT3|grep -i SuChWoRt4</tt>''' |
|||
[[Category:Software]] |
|||
[[Category:GNU]] |
|||
[[Category:Linux]] |
|||
=== manpage === |
|||
<man>grep</man> |
|||
{{manpage}} |
|||
=== jargon === |
|||
<jargon /> |
<jargon /> |
Latest revision as of 02:58, 11 November 2007
The grep command searches one or more input files for lines containing a match to a specified pattern.
How can I list just the names of matching files?
- grep -l 'main' *.c
How do I search directories recursively?
- grep -r 'hello' /home/gigi
Suppose I want to search for a whole word, not a part of a word?
- grep -w 'hello' *
How do I output context around the matching lines?
- grep -C 2 'hello' *
How can I search in both standard input and in files?
- Use the special file name `-':
- cat /etc/passwd | grep 'alain' - /etc/motd
more on
http://www.gnu.org/software/grep/doc/grep.html
try
$ cat FILENAME|grep SUCHWORT1|grep UND_SUCHWORT2|grep -v OHNE_SUCHWORT3|grep -i SuChWoRt4
manpage[edit]
<man>grep</man>
jargon[edit]
<jargon />