grep

Searching With grep

  • G lobal R egular E xpression P rint

    • sed (S tream ED itor) terminology

  • Its usage has become a verb: to grep (predates to google)

  • Simplest usage: all occurences of jfasch in /etc/group

    $ grep jfasch /etc/group
    adm::4:root,adm,daemon,jfasch
    portage::250:portage,jfasch
    jfasch:x:1000:
    

Regular Expressions

  • More capable search than a simple word

  • Shell quoting in order, to avoid shell expansion

  • Example: jfasch, as a member of a group (and not the group itself)

    $ grep '^.*[:,]jfasch' /etc/group
    adm::4:root,adm,daemon,jfasch
    portage::250:portage,jfasch
    

Options

Option

Description

-i

Case insensitive pattern

-l

Show only filename where pattern was found, not the hit itself

-n

Show line numbers

-r

Search entore directory tree(s), recursively

-v

Negation: show only lines where pattern is not found

More About Regular Expressions