O'Reilly logo

SAMS Teach Yourself Unix in 10 Minutes by Robert Shimonski

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

Using [] and ^

In this section, we will learn more about REs, particularly when using and negating ranges using the [] and ^ characters.

You've noticed that the robtest.txt file you created and have been using has the years 1899 through 1999 inside of it. We will use grep again in conjunction with REs to match the years that only fall in the 2000 range. To do this, you can specify a range using REs as follows: [<starting point>-<ending point>]. The starting and ending points can be numbers or ranges within the alphabet.

For example, type the following:

					> grep "1[8-9]9[0-9]*" robtest.txt
					1999
					1899
				

This example lets Unix search robtest.txt for anything that is in the 1[8-9][9-0] range, which is only 1999 and 1899. It couldn't be anything from ...

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