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

RLENGTH and RSTART

The match function searches for a given string/pattern/regular expression in the input string and returns a positive value when a successful match occurs. It sets the two special variables, RSTART and RLENGTH, that indicate where a regular expression begins and ends:

  • RSTART: This stores the starting location of the search string/pattern
  • RLENGTH: This stores the length of the search string/pattern

The contents of the RLENGTH or RSTART variable are set/changed when the match function is invoked.

In the following example, we use the match function to search for a pattern and print all that is present before and after the pattern—as well as the pattern itself, separately—as follows:

$ vi match.awkBEGIN     {    regex="Singh"; } ...

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