APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2003/09/03 grep


© September 2003 Tony Lawrence

Grep is used to search inside other files. The awful name comes from "Global Regular Expression Print", because although its simplistic use is much like Windows "FIND" command, it is actually much more powerful.

So while you could use it like:

grep "hello" *.c
 

it can also do much more complicated searches based on wild card patterns:

grep '^[Hh]ello  *' *.c
 

which would look for "hello" or "Hello" at the beginning of a line followed by any number of spaces.

Unix people sometimes use grep in ordinary conversation, but it' s easy to look like a wannabe with this one, so don't try it while you are still wet behind the ears.

One of the questions people ask about grep is how to use it to search through files in sub-directories. You might think there's a simple, easy way to do that, but actually it can be pretty complicated. See How can I recursively grep through sub-directories? for some ways to do it.

In older Unix books, you'll sometimes find a hint to use "fgrep" instead of grep if you aren't using wildcards. That advice is no longer valid, so ignore it.


Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> Unix and Linux grep


Inexpensive and informative Apple related e-books:

Photos: A Take Control Crash Course

Take Control of iCloud, Fifth Edition

Are Your Bits Flipped?

Take Control of OS X Server

Take Control of IOS 11




More Articles by © Tony Lawrence




Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us


Printer Friendly Version





One in a million is next Tuesday. (Gordon Letwin)




Linux posts

Troubleshooting posts


This post tagged:

Shell

UnixWords



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode





SCO Unix Sales, Support, & Service

Phone:  707-SCO-UNIX (707-726-8649Toll Free: 833-SCO-UNIX (833-726-8649)
www.SCOsales.com