AboutWelcome to Free Software Daily (FSD). FSD is a hub for news and articles by and for the free and open source community. FSD is a community driven site where members of the community submit and vote for the stories that they think are important and interesting to them. Click the "About" link to read more...
The term regular expressions refers to a type of search language. You'd use it to search for text strings that match certain defined patterns. So, if you need to search through a document for email addresses, IP addresses, credit card numbers, Social Security numbers, etc., you'd define a regular expression.
I recently came across expect (the expect package in Debian and Ubuntu): a powerful utility that can script interactive operations. If you're not familiar with TCL syntax, you can get autoexpect from Wi-Fizzle.com. This spawns a shell, and then records everything you do in that shell.
The Linux utility sed provides a great way to substitute text strings in a file. Using the "s" option and by listing the current string and the string to use as the new text allows sed to perform this task.
By and large, most Red Hat Linux systems will have Bash as the default shell. Bash is a darn great shell, but this article is about another equally great shell, called Z-Shell, that has most of the attributes of Bash, but in some cases goes the extra mile to give you the flexibility to customize your shell more than Bash allows.
Suppose you have a PDF document that was made using a scanner, or otherwise consists of image data but doesn't have text data. Such a PDF can't be searched by PDF readers or desktop search applications.
Here's a brief example of applying a regex, drawn from the UNIX command-line utility grep, which searches for a specified pattern among the content of one or more UNIX text files. The command grep -i -E '^Bat' searches for the sequence beginning-of-line (indicated with the caret, [^]), followed immediately by upper- or lowercase letters b, a, and t (the -i option ignores case in pattern matches, so B and b are equivalent, for instance). Hence, given the file heroes.txt: