Grep

From Wsms

Jump to: navigation, search

Note: This page should be titled grep (all lowercase). It is Grep due to technical limitations of Mediawiki.

grep looks for text or patterns

Common Usage

List files containg some literal text:

[ggeller@harrison svn-book-html-chunk]$ grep -l -i ignore *.html
index.html
svn.advanced.confarea.html
svn.advanced.externaldifftools.html
...

Advanced usage, egrep

egrep lets you use regular expressions. For example, it the file test.txt contains:

blahblahblahblah/usr
blahblahblahblah/usr/blahblahblahblah

You use the following to find the line that ends in /usr:

ggeller@roosevelt:~/tmp/test$ grep -e '/usr$' test.txt
blahblahblahblah/usr

This one finds all the lines that don't start with a period '.'

grep -e '^[^\.]'

The first ^ means at the start of the line. The [^\.] means NOT the literal '.' character.

see also

man grep

Personal tools