# AWK scripting problem - appending values

**URL:** <https://community.unix.com/t/awk-scripting-problem-appending-values/156404>\
**Category:** Shell Programming and Scripting\
**Created:** [September 30, 2005, 5:11am UTC](https://community.unix.com/t/awk-scripting-problem-appending-values/156404 "2005-09-30T05:11:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rowntree](https://community.unix.com/letter_avatar/rowntree/32/5_5575768a8748004e209b776fc1b2916d.png) [@rowntree](https://community.unix.com/u/rowntree)\
**Post date:** [September 30, 2005, 5:11am UTC](https://community.unix.com/t/awk-scripting-problem-appending-values/156404/1 "2005-09-30T05:11:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![futurelet](https://community.unix.com/letter_avatar/futurelet/32/5_5575768a8748004e209b776fc1b2916d.png) [@futurelet](https://community.unix.com/u/futurelet)\
**Post date:** [September 30, 2005, 3:02pm UTC](https://community.unix.com/t/awk-scripting-problem-appending-values/156404/2 "2005-09-30T15:02:50Z")

</div>

This is more difficult than it seems at first.

```nohighlight
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
}

```

---

<div class="post-metadata">

**Author:** ![rowntree](https://community.unix.com/letter_avatar/rowntree/32/5_5575768a8748004e209b776fc1b2916d.png) [@rowntree](https://community.unix.com/u/rowntree)\
**Post date:** [October 3, 2005, 3:04am UTC](https://community.unix.com/t/awk-scripting-problem-appending-values/156404/3 "2005-10-03T03:04:18Z")

</div>

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

Thanks very much for you help

😃
