AWK scripting problem - appending values

ABC:10:A1:ABCA110
ABC:10:A1:ABCA110
ABC:20:A1:ABCA120
DEF:20:D1:DEFD120
GHI:30:G1:GHIG130
GHI:40:G1:GHIG140
JKL:30:J1:JKLJ130
MNO:10:M1:MNOM110

What I'm trying to do is look through a file that consists of four columns (as above). As you can see there are duplicates in
the file, i.e. line 1 & 2. With this scenario I need to change column three, so the first line appends an 'A' to the
value of 'A1'. And then the second line a 'B' is appended to the value 'A1'. The changed output should look like:

ABC:10:A1A:ABCA110
ABC:10:A1B:ABCA110

If there are more then just two duplicates the appended value should be the next letter of the alphabet, and so on.

How the hell can I do this using awk? I've tried and didn't get remotely close to achieving the above.

This is more difficult than it seems at first.

BEGIN { FS=OFS=":" }

{
  if ( !Count && prev == $0 )
    Count = 1
  prnt( prev )
  if ( prev != $0 )
    Count = 0
  prev = $0
}

END { prnt( prev ) }  

function prnt( line,     save )
{
  save = $0;  $0 = line
  if ( Count )
    $3 = $3 sprintf("%c", 64 + Count++ )
  print
  $0 = save
}

Wow...thanks for your reply I will give this a go

Thanks very much for you help

:smiley: