Given the plain text file with lines
bli foo bla
abc
dfg
bli foo bla
hik
lmn
what sed or awk magic transforms it to
bli foo_01 bla
abc
dfg
bli foo_02 bla
hik
lmn
so that every occurence of 'foo' is replaced by 'foo_[occurence number]'.
awk '!/foo/||sub(/foo/,"&_"++_)' infile
Use gawk, nawk or /usr/xpg4/bin/awk on Solaris.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With