Last Updated: 14 Oct 2023

   |   

Author: dordal

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
server-tech:quick-introduction-to-grep [Jun 23, 2009 04:55 AM]
dordal
server-tech:quick-introduction-to-grep [Oct 14, 2023 04:43 AM]
dordal old revision restored (Nov 21, 2020 10:39 PM)
Line 1: Line 1:
 += Quick Introduction to grep/egrep/fgrep = 
  
 +grep is a command line utility that lets you search for certain patterns in files, and pull out the lines that match said patterns. grep supports a limited set of regular expressions, but egrep (it's cousin) supports a more complete set. fgrep (the other cousin) is grep without regular expression support, making it much faster. Realistically, you'll almost certainly want to use egrep or fgrep, not normal grep.
 +
 +Standard grep/egrep/fgrep output isn't terribly useful, so you'll want to specify some options to make it more so:
 +
 +''egrep -rin //regexp// files''
 +
 +That says use egrep recursively, ignore case, and print line numbers with the output.
 +
 +grep [[http://www.regular-expressions.info/grep.html|usually uses a POSIX style regular expression parser]], but may not always, depending on your platform. Modern versions (GNU grep 2.5.1 and greater) can use Perl-style regular expressions with the -P flag.
 +
 +''grep -v'' will get all lines that //don't// match your regular expression, which can frequently be useful.
 +
 +grep is particularly useful for parsing log files (e.g. apache logs, etc.). Angie of ShowMeAnalytics has written a great article on [[http://showmeanalytics.com/?p=19|using grep and other tools]] to parse log files.