header image
Home arrow LUG How Tos arrow How To Using grep
How To Using grep Print
Feb 17, 2008 at 07:01 PM
How To Using grep.
Impress tutorial is here.
Image

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

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

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
Image

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

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
Image

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
        + * . [] () {} ? \ + - ~ ^ $
Image

More info
  * Lots more options
      man grep

EC_LUG -Eau Claire Linux users group is an informal group of Linux and open source software enthusiasts.

We meet each Thursday at 7 p.m. at  420 Cafe, 420 Washington Ave. Eau Claire, Wisconsin.

Linux 101:
What's All The Fuss? video...

Mac vs. PC: How Would Linux Fit?
video1...

video2...
video3...

Linux User GroupsLug Link Logo