79548147

Date: 2025-04-01 09:04:36
Score: 1
Natty:
Report link

The answer to my question is that sub was not looking in the right place, so to speak! This works:

$ printf "a ab c d b" | awk '{for (i=1;i<=NF;i++) if ($i=="b") sub("b","X",$i); print}'
a ab c d X

The third sub argument is the target for replacement.

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: user2138595