O'Reilly logo

Linux and Unix Shell Programming by David Tansley

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

7.6. Matching ranges or sets using []

To match certain specific characters or ranges of characters use []. You can separate the different characters that you want to match inside the brackets with commas; this is not mandatory (some systems do moan if you don’t use commas on complex expressions) but it does make the pattern more readable.

To specify a range of characters use the dash (-). This specifies a set or range where the range starts on the left-hand side of the dash and finishes on the right-hand side of the dash.

You should always use the [] when you want to home in on a string match. Suppose we wanted to match any single number, we could use:

[0123456789] 

However, there is an easier method by using the dash (-):

[0-9] 

or any lower ...

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