}
}
} I'm having probs with the internal function 'gsub' for AWK. All other
} functions seem to work ok, but I'm getting syntax errors for gsub. Is
} there anyone who is familiar with this function who can tell me why I
} can't use it? Or, if I can use it, tell me wh} ere to find out exactly
} how? The AWK man pages don't seem to tell me anything.
}
} Please mail replies to me or here.
>From the nawk(1) manpage (may or may not be installed at SoCS any more):
gsub(for,`repl,`in)
behaves like sub (see below), except that it
replaces successive occurrences of the regular
expression (like the ed global substitute com-
mand).
[ ... ]
sub(for,`repl,`in)
substitutes the string repl in place of the first
instance of the regular expression for in string
in and returns the number of substitutions. If in
is omitted, nawk substitutes in the current record
($0).
----
... therefore:
bag_end|bash:~ 49 > echo "testy woo testy woo testy woo testy woo testy woo testy woo" | nawk '{ sub(/est/, "arg"); print }'
results in
targy woo testy woo testy woo testy woo testy woo testy woo
... and:
bag_end|bash:~ 50 > echo "testy woo testy woo testy woo testy woo testy woo testy woo" | nawk '{ gsub(/est/, "arg"); print }'
results in
targy woo targy woo targy woo targy woo targy woo targy woo
Okay? It's optional to specify the target string; by default, $0 is taken
(the current work line).
-- Colin.