Regular Expressions in the Unix Shell
(Page 1 of 4 )
Searching. Now there is a task I am sure you do on a daily basis. In Shell programming, searching is very important; fortunately, you have a reliable set of tools to help you out. These are the regular expressions. And this article is the thirteenth in a series focusing on various aspects of UNIX.
These are bound mostly to text processing. Because the universal language used in UNIX is the shell, regular expressions come to play an important role when you work under any kind of operating system based on the UNIX shell. A regular expression is a text pattern matching language. Although initially it was first used and developed in UNIX, today it is used in other contexts as well.
In fact, regular expressions are the number one tool used in most text-handling programs. They are used for pattern matching in domains such as genetic codes, web development and more. This means that regular expressions have managed to become close to the perfect tool. Nevertheless, this was the result of years of improvement. As you would expect from something that has been around and improved upon for that long, there are a couple of versions.
First, there is the basic version from which all regular expressions began. After a while, POSIX standards for the regular expression were defined. With this definition, regular expressions gained a little addition and improvement, creating the extended version.
At the end of the 90s, a powerful script language emerged under the name of Perl. This language contributed its own additions and modifications to regular expressions. This is how the Perl-compatible regular expression appeared. Today we only use the basic version, to maintain backward compatibility with the older scripts. You will use them by default with the following commands: expr, grep, sed. The expr I presented in a previous article, while the rest will be covered in this and the next article.
If you want to use the extended version, you can do so with the egrep command or the sed -r option and the grep -E option. The awk programming language, which will be the subject of a future article, also uses the extended regular expression. Today I will only cover the extended version. However, if you are interested, there are a couple of articles about the other ones also here on the network. Just search for them!
Next: Extended Regular Expressions >>
More Server Administration Articles
More By Gabor Bernat