Do manual do GNU awk 9.1.3 Funções de manipulação de seqüências :
... the third argument to
sub()
must be a variable, field, or array element. Some versions of awk allow the third argument to be an expression that is not an lvalue. In such a case,sub()
still searches for the pattern and returns zero or one, but the result of the substitution (if any) is thrown away because there is no place to put it. Such versions of awk accept expressions like the following:
sub(/USA/, "United States", "the USA and Canada")
For historical compatibility, gawk accepts such erroneous code. However, using any other nonchangeable object as the third parameter causes a fatal error and your program will not run.
Então, a resposta é usar uma variável:
awk 'BEGIN{t = "banana"; sub(/ana/,"anda",t); print t}'
bandana