My file contains data like this:

```
A foo(a)
A foo(a)
B foo(b)
A foo(a)
B foo(b)

```

I want them to be converted to

```
A foo(a1)
A foo(a2)
B foo(b3)
A foo(a4)
B foo(b5)

```

At present, I think an approach to use IF with line number ($), and the sed the replace with sed. But, I am not sure how to do it.