LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 01-21-2013, 12:32 AM   #1
bison72
LQ Newbie
 
Registered: May 2012
Posts: 5

Rep: Reputation: Disabled
Smile 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.
 
Old 01-21-2013, 01:15 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
What have you tried?
 
Old 01-21-2013, 01:31 AM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
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/
 
Old 01-22-2013, 11:34 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
count characters mirzasoltan Linux - Newbie 5 10-24-2012 11:15 AM
[SOLVED] MySql order by COUNT and list the total count countrydj Programming 3 07-19-2012 01:21 PM
[SOLVED] Speeding up a script to count number of repeat characters in each column tweed08 Linux - Newbie 4 03-21-2012 10:15 AM
Command to count all characters in file. guif Linux - Newbie 4 03-26-2010 09:44 AM
characters count in a string powah Programming 3 07-19-2007 03:03 PM


All times are GMT -5. The time now is 10:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration