I want to write a script (shell script or awk) to print $1 (first field) of duplicate entry all to gather and then use the last value to find difference between last and first entry or may be note the difference of value at every duplicate entry. 

For example my files has following entries:

```
counter1 is 100
counter2 is 200
counter3 is 300
counter1 is 1000
counter2 is 2000
counter3 is 3000
counter1 is 10000
counter2 is 20000
counter3 is 30000

```

I want to print:

```
counter1 is 100
counter1 is 1000
counter1 is 10000
counter2 is 200
counter2 is 2000
counter2 is 20000
counter3 is 300
counter3 is 3000
counter3 is 30000

```

Now each counter has some value incremented so I want to find difference between each value of same counter:

```
counter1 is 100
counter1 is 1000 | difference 1000-100 = 900
counter1 is 10000| difference 10000-100= 9900

```

I was able to print duplicate entries but not able to bunch them, its appearing in the same sequence as file has. 

```
MacBook-Air:linuxscripts jimdev$ awk 'NR==FNR && a[$1]++ {b[$1];next} $1 in b' FS=" " countr.txt countr.txt 

counter1 is 100
counter2 is 200
counter3 is 300
counter1 is 1000
counter2 is 2000
counter3 is 3000
counter1 is 10000
counter2 is 20000
counter3 is 30000

```