O'Reilly logo

Beginning Unix by Paul Weinstein, Jeremy C. Reed, Craig Zimmerman, Joe Merlino, Paul Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8

Advanced Tools

In Chapter 6, you learned basic Unix commands and how they work. Now you'll build on that knowledge and expand your command library. This chapter tackles advanced commands and regular expressions (formulas for matching strings that follow specific patterns). Regular expressions are important, and they're also quite challenging when you're just learning about them. Don't worry, though, because this chapter provides a good foundation for your learning.

Regular Expressions and Metacharacters

A regular expression is a syntactical set or phrase that represents a pattern of text or strings. Regular expressions enable you to represent a varying array of characters with a much smaller set of predefined characters. They often include metacharacters—characters that represent another set or group of characters or commands.

No discussion of regular expressions and metacharacters is useful without examples, so create a file called /tmp/testfile that you can use as you work your way through this chapter: Here's what to put in the file (note the capitalization and punctuation):

Juliet Capulet
The model identifier is DEn5c89zt. Sarcastic was what he was. No, he was just sarcastic. Simplicity
The quick brown fox jumps over the lazy dog
It's a Cello? Not a Violin?
This character is (*) is the splat in Unix.
activity
apricot
capulet
cat
celebration
corporation
cot
cut
cutting
dc9tg4 eclectic housecat persnickety The punctuation and capitalization is important in this example. simplicity ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required