October 2001
Intermediate to advanced
1040 pages
22h 50m
English
The sub and gsub Functions. The sub function matches the regular expression for the largest and leftmost substring in the record, and then replaces that substring with the substitution string. If a target string is specified, the regular expression is matched for the largest and leftmost substring in the target string, and the substring is replaced with the substitution string. If a target string is not specified, the entire record is used.
FORMATsub (regular expression, substitution string); sub (regular expression, substitution string, target string) |
1 % nawk '{sub(/Mac/, "MacIntosh"); print}' filename 2 % nawk '{sub(/Mac/, "MacIntosh", $1); print}' filename |
EXPLANATION ... |