Content added Content deleted
imported>mutante mNo edit summary |
imported>Kunda m (cosmetics w/ <tt> | whaddya think?) |
||
Line 4: | Line 4: | ||
How can I list just the names of matching files? |
How can I list just the names of matching files? |
||
⚫ | |||
⚫ | |||
How do I search directories recursively? |
How do I search directories recursively? |
||
⚫ | |||
⚫ | |||
Suppose I want to search for a whole word, not a part of a word? |
Suppose I want to search for a whole word, not a part of a word? |
||
⚫ | |||
⚫ | |||
How do I output context around the matching lines? |
How do I output context around the matching lines? |
||
⚫ | |||
⚫ | |||
How can I search in both standard input and in files? |
How can I search in both standard input and in files? |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Line 32: | Line 30: | ||
try |
try |
||
<pre> |
|||
$ cat FILENAME|grep SUCHWORT1|grep UND_SUCHWORT2|grep -v OHNE_SUCHWORT3|grep -i SuChWoRt4 |
'''<tt>$ cat FILENAME|grep SUCHWORT1|grep UND_SUCHWORT2|grep -v OHNE_SUCHWORT3|grep -i SuChWoRt4</tt>''' |
||
</pre> |
|||
Revision as of 23:05, 10 February 2006
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