O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

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

Zero or one

The zero or one operator (?) matches occurrences of the preceding character zero or one time. For example, we use ? to mark the e as an optional character to match the Jean or Jan string, as follows:

$ echo -e "Jean\nJan\nJeean" | awk '/Je?an/'

The output on execution of the preceding code is as follows:

JeanJan

A summary of the unary operator for repetition is as follows:

Pattern

Matches

A?

Matches the single A or null string

AB?C

Matches AC or ABC

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