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

Concatenation using alternation operator within parentheses

Parentheses can be used to concatenate regular expressions using the '|' alternation operator. In this, we simply place two or more regular expressions separated using the alternation operator pipe, '|', within parentheses to match any of them. For example, in the given example we print lines with the JaneEmilyAna, or Victor employee name from the emp.dat file, as follows:

$ awk '/(Jane|Emily|Ana|Victor)/{ print }' emp.dat

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

Jane    Kaur    9837432312  jane@gmail.com      F   hr      1800Ana     Khanna  9856422312  anak@hotmail.com    F   Ops     2700Victor  Sharma  8826567898  vics@hotmail.com    M   Ops     2500Emily   Kaur    8826175812  emily@gmail.com     F   Ops     2100

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