awk String manipulation functions String text substitution


Example

SUB function allows to substitute text inside awk

sub(regexp, replacement, target)

where regexp could be a full regular expression

$ cat file
AAAAA
BBBB
CCCC
DDDD
EEEE
FFFF
GGGG
$ awk '{sub("AAA","XXX", $0); print}' file
XXXAA
BBBB
CCCC
DDDD
EEEE
FFFF
GGGG