Pattern Matching

For those familiar with regular expressions in other programs—including Perl, awk, grep, and sed—remember the context, but forget the format. The format of regular expressions is different. A fairly easy way of converting the format into the shell format so that it can be used within a shell script exists. The %P format of printf converts the formats for most versions of UNIX, but it is not an option with older versions of printf. The printf command is discussed in Chapter 10, “Output Control.”

The following is an example of printf with the %P modifier. It shows the shell equivalent of the regular expression obr.*$. This regular expression matches any string containing obr and then 0 or more characters up to the end of the line: ...

Get Korn Shell Programming by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.