I have tried several awk arrays but just can´t get my head around it. Having a file with 4 colums the awk skript should count for each line how many times the value in column 2 appears.
Input File
A1^ABC^173^2012
A2^BDK^153^2013
A3^AFD^223^2012
B1^ABC^083^1999
B2^KLX^033^2012
B3^ABC^593^2003
B4^KLX^323^2001
So as result I want to print the counter for the value in column 2 at the end of each line. E.g line one has value "ABC" in column2. "ABC" appears 3 times in the entire file and is printed at the end of the line.
Output File
A1^ABC^173^2012^3
A2^BDK^153^2013^1
A3^AFD^223^2012^1
B1^ABC^083^1999^3
B2^KLX^033^2012^2
B3^ABC^593^2003^3
B4^KLX^323^2001^2
Hope anyone got an idea on how to solve it.
Cheers