|
Feb 17, 2008 at 07:01 PM |
How To Using grep. Impress tutorial is here.

What does grep do? * Prints lines matching a pattern or * Prints files that match a pattern * Searching File contents Program results

Using grep * A file * Or group of files # grep “FINDME” file.txt # grep “FINDME” * * Program output (std input) # ls | grep “FINDME”

Options for searching * -i – ignore case = “FINDME” matches FindMe, FINDME, findme. * -v – reverse lookup = Find all non-matches * -w – Match a word = Spaces or punctuation must surround search string

Options for displaying results * Normally, matching lines are displayed * Other possibilities = -c – count results = -L – display files without match = -l – display files with match

Changing formats * -n – display line number * -h – don't print file name * -o – show only the matching part of the line Useful with regular expressions

A word on Regular Expressions * Extremely powerful and useful * Can be confusing and difficult * grep uses regular expressions by default What this means to you: Special Chars must have a '\' before them + * . [] () {} ? \ + - ~ ^ $

More info * Lots more options man grep
|