×
Create a new article
Write your page title here:
We currently have 3,189 articles on s23. Type your article name above or create one of the articles listed here!



    s23
    3,189Articles

    Grep: Difference between revisions

    Content added Content deleted
    imported>mutante
    mNo edit summary
    imported>mutante
    mNo edit summary
     
    (6 intermediate revisions by 2 users not shown)
    Line 3: Line 3:
    * http://www.gnu.org/software/grep/
    * http://www.gnu.org/software/grep/


    How can I list just the names of matching files?
    How can I list just the names of matching files?
    :'''<tt>grep -l 'main' *.c</tt>'''


    grep -l 'main' *.c


    How do I search directories recursively?
    How do I search directories recursively?
    :'''<tt>grep -r 'hello' /home/gigi</tt>'''


    grep -r 'hello' /home/gigi


    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?
    :'''<tt>grep -w 'hello' *</tt>'''


    grep -w 'hello' *


    How do I output context around the matching lines?
    How do I output context around the matching lines?
    :'''<tt>grep -C 2 'hello' *</tt>'''


    grep -C 2 'hello' *


    How can I search in both standard input and in files?
    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>'''
    Use the special file name `-':

    cat /etc/passwd | grep 'alain' - /etc/motd




    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>




    Line 40: Line 38:
    [[Category:GNU]]
    [[Category:GNU]]
    [[Category:Linux]]
    [[Category:Linux]]

    === manpage ===

    <man>grep</man>

    {{manpage}}

    === 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>

    see also: mansearch, man2html


    jargon[edit]

    <jargon />

    Cookies help us deliver our services. By using our services, you agree to our use of cookies.
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.