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: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access