AWK – Regular Expression Operators

  • Post author:
  • Post category:AWK
  • Post comments:2 Comments
AWK - Regular Expression Operators

This topic is about AWK – Regular Expression Operators.

This example explains the two forms of regular expressions operators.

Match

It is represented as ~. It looks for a field that contains the match string. For instance, the following example prints the lines that contain the pattern 9.

Example

[jerry]$ awk '$0 ~ 9' marks.txt

On executing this code, you get the following result −

Output

2) Rahul   Maths    90
5) Hari    History  89

Not Match

It is represented as !~. It looks for a field that does not contain the match string. For instance, the following example prints the lines that do not contain the pattern 9.

Example

[jerry]$ awk '$0 !~ 9' marks.txt

On executing this code, you get the following result −

Output

1) Amit     Physics   80
3) Shyam    Biology   87
4) Kedar    English   85

In this topic we learned about AWK – Regular Expression Operators. To know more, Click Here.

This Post Has 2 Comments

Leave a Reply