May 2000
Beginner
761 pages
18h 20m
English
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.
Format
sub (regular expression, substitution string); sub (regular expression, substitution string, target string)
1 % awk ' {sub(/Mac/, "MacIntosh");print} ' filename 2 % awk ' {sub(/Mac/, "MacIntosh", $1); print}' filename |
Explanation ...
Read now
Unlock full access