Hot answers tagged

4 votes
Accepted

Remove duplicates by adding numerical suffix

awk can take arbitrary array indices - even a whole record ("line"). Make a regex match for tag: and start the counter, but correct by one due to the first match awk '$0 ~ /^tag:/ { n[$0]++?$...
FelixJN's user avatar
  • 12.9k
3 votes

Remove duplicates by adding numerical suffix

Here we go, exactly as required: awk ' NR==FNR{ if (/^tag:/) { a[$1]++ } next } { c=--a[$1] if (c>0) { printf "%s-%....
Gilles Quénot's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible