Are there any online grep tutorials that would feature some online tool for performing exercises? For example, having some predefined text sample and being told what patterns to find and so forth? It would be a very useful tool for practical learning of grep in a predictable environment.

3 Answers
3

If you're looking for an online environment to practice your pattern matching using regex, there are a number of nice resources that allow you to play around with expressions for a given portion of text. Off the top of my head, there is: regex pal or rubular.

In terms of exercises, one idea is to search for questions tagged with [regex] on stack overflow. There are new regex questions of the form: "I have this text, I want to match this part of it" being posted all the time. You could just pick any one you feel comfortable with and try to work through it in your own time. There is also the benefit of being able to compare your solutions with the accepted answers.

To get you started there is the regex site which has a variety of great resources.

Note: although you asked about the grep command in particular, since it only utilises a subset of what regex has to offer in terms of pattern matching, I figured you would be better served focusing on regex in general. Also, there are varieties of grep that include a wider regex lexicon, such as egrep, which you might need to use eventually. See man grep for more details on its additional features/variations.

Just a suggestion that satisfies the online and regex portion of your question:

http://gskinner.com/RegExr/ is a pretty friendly regex testing tool. It highlights results on the fly as you create your regex pattern. I use it regularly (there's also a desktop version using Adobe AIR)

As tojrobinson said, there's only a subset of regex implemented in grep, but this should be helpful for your learning process as it's instant feedback.