awk '{
for (i=1;i<=NF;i++) {
if ($i == "DATA") printf("%s%s", "NO"++n, OFS);
else printf("%s%s", $i, OFS)
if (i==NF) printf "\n"
}
}' file > outFile
OR, as Glenn Jackman rightly points out, this can be collapsed to
awk '{for (i=1; i<=NF; i++) if ($i=="DATA") $i = "NO" ++n} {print}' file > outFile
I leave my original version in place to show an alternative (but overloaded) approach; -)
Hope this helps.
source
share