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 |
---|---|
|
Case insensitive pattern |
|
Show only filename where pattern was found, not the hit itself |
|
Show line numbers |
|
Search entore directory tree(s), recursively |
|
Negation: show only lines where pattern is not found |
More About Regular Expressions¶
Pattern language ⟶ finite state machine
Much like programming
Deserves a course of it own
Perl Regular Expressions