in reply to Re^2: Dear Monks
in thread Dear Monks

sivaraman,
But i want the output like

Then you did a poor job of explaining your problem. I can see other potential things you haven't told us like order. Do you want the most frequent items first? Should the country codes (assuming US, GB and UK are country codes) be listed in alphabetical order on a line or should they be in the order they appeared in the file or does it matter at all?

In your first example, you had two lines that were 'abcd,US' and your desired output was '2 abcd US'. What would you have wanted if the input was

abcd,US abcd,US abcd,GB

Based off your poor description so far, I would guess '3 abcd US, GB' but I wonder if it is important to know that 2 of the 3 came from US?

In general, hashes allow you to keep track of distinct items (the abcd portion) and arrays help you maintain order. When you do a better job of explaining what you want, someone will likely jump in and provide a solution but you should be able to start exploring bart's solution on your own as well.

Cheers - L~R