The Open Source Swiss Army Knife

/unix/commandline/
/unix/commandline/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /unix   /commandline 
Permalink: grep.htm
Title: add
article options : please login   |  print view

  1. grep
  2. egrep

grep

  1. ps -x | grep "rpc.nfsd"
    finds the process titled "rpc.nfsd"

    Where a program needs an extra filename, there is a bug in grep that it won't give the name of the file where they find a match unless there are at least two filenames on the command line. Use /dev/null to ensure that grep will always see more than one :
    # grep "whatever" * /dev/null
  2. -l -->
  3. -i --> case insensitive
  4. grep ` ADS' input_file
    searchs for the word ADS, as it is preceded by a space
  5. grep -r quote *
    my favorite, use it so often: does a recursive search for that word across directoris. If there are spaces, use quotes around your search term
  6. ps -aux |grep bin |grep -v grep|awk '{print $1;}'
    finds user owning process containing keyword "bin"
  7. -v says "select non-matching lines" or invert it not-to-search instead
    grep -lr quote *
    print filenames of matches, not actual line
  8. --binary-files=TYPE, for example grep -r --binary-files=without-match va_ *
    skip matches in binary files
  9. --exclude=PATTERN
    Recurse in directories skip file matching PATTERN.

egrep

this grep is the only one that supports syntax like egrep '(John|Fred)' phone.txt

egrep Beyer|SBM input_file
really does just look for either Beyer or SBM
no square brackets required
egrep [0-9]\{3,0\} input_file
searches for a span of three or more numbers 0 to 9

Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top