Count characters and list down the number
Hi there,
In a vi file, I have one column as shown below: A A A A A A B B B C C C C C I would like to list down the number according to different characters next to the column as column 2: A 1 A 2 A 3 A 4 A 5 A 6 B 1 B 2 B 3 C 1 C 2 C 3 C 4 C 5 Is there any way I can do it like this? Thank you for your kind help. |
What have you tried?
|
If you're going to script this, you'll find these useful
http://rute.2038bug.com/index.html.gz http://tldp.org/LDP/Bash-Beginners-G...tml/index.html http://www.tldp.org/LDP/abs/html/ |
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. |
All times are GMT -5. The time now is 10:17 PM. |