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

The sub (regex, replacement, string) function

GAWK and NAWK have seed-like string substitution functions, such as sub, gsub, match, and gensub. The sub function is used to substitute an original substring with a new substring from the given string. The original substring can be a regular expression. If the string in which the substitution is to be performed is not given, then $0 is assumed to be the searched string.

The sub() function only changes the first occurrence of the matched substring with the replacement substring once in a line. If the regular expression is not enclosed in forward slashes in the first argument of the sub function, then it is treated as a variable containing a regular expression. If the special character & is used ...

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