To start with, please use ***
[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do
not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
By "vi file", you really mean a text file created in
vi, correct?
So are you looking to do this operation in
vi*, or in the shell, or what? And is the input always sorted properly, or can it be sorted, or does each entry have to be counted wherever it lies in the file?
You need to always be clear about the exact requirements and the environment you're using if you want accurate help.
In any case, this could be done very simply in
awk. Or
perl. Although it could even be done entirely in the shell if necessary.
* And is "
vi", the original or actually the more advanced
vim? I'm not sure this kind of thing could even be done in the former, and you'd probably have to write up a fairly complex function for the latter.