grep

Started by forTwist, September 06, 2005, 06:12:11 PM

Previous topic - Next topic
Hey, I'm a total newbie to Linux, so take it easy...

I'm confused with the command "grep," I don't get what makes it so powerful... Does anyone have resources or just a short tutorial on how to use it and why it's so great.  I tried "man grep," but it's like twenty billion pages and I can never read those pages right.

I don't know if grep itself is the key, so much as regular expressions in general (grep = get regular expression).

It can be a complex topic, but many languages use them (perl for example).

the sed program uses them, etc (and of course the grep commands, egrep, grep, fgrep etc use them).

What they're useful for is that they make things so much easier to search/process/etc once you learn it.

You're right, it's a lot to absorb. I'll see if I can get some more info on it for you (right after I post this).

"My Terminal is my Soul"

http://www.regular-expressions.info/tutorial.html

http://en.wikipedia.org/wiki/Regular_expression <-- pretty nice

Also check out the bash shell (and others) (since it uses regular expressions too).

I might add that this topic could probably fill a book (or more), so don't feel too bad if you don't grasp it all.


Hopefully the above will get you a good start on it (the idea of wild cards are related btw).
"My Terminal is my Soul"

Oh and I forgot one thing..

You asked about grep specifically.

Once you learn regular expressions, it's more powerful, but the idea is that you can search through files to match certain patterns. I use it a lot when coding.

For example:

I have thousands upon thousands of lines in a couple projects, and if I need to replace something in every file that matches a certain pattern, I can do it in one command. OR I can search for a pattern to find out which files I need to open, OR I can search for a function to see which file it's in ... etc. The possibilities are endless :)

So I'd start with regular expressions and then play around with grep.

Hope that helps!
"My Terminal is my Soul"

SMF spam blocked by CleanTalk