LinuxQuestions.org
Visit Jeremy's Blog.
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-28-2017, 02:48 AM   #1
hoi
LQ Newbie
 
Registered: Jun 2013
Posts: 29

Rep: Reputation: Disabled
How to count different number in a column and print that value?


I have data like this..

0.493
0.493
0.493
0.500
0.500
0.702
0.702
0.702
0.702
0.800
0.800
0.866
0.866
0.866
0.866
0.866
0.866

The frequency(the number of same patern) of the number is not known to me. I want to extract the below information

0.493 3
0.500 2
0.702 4
0.800 2
0.866 6

I would greatly appreciate any help.
 
Old 01-28-2017, 03:02 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,350
Blog Entries: 11

Rep: Reputation: 3312Reputation: 3312Reputation: 3312Reputation: 3312Reputation: 3312Reputation: 3312Reputation: 3312Reputation: 3312Reputation: 3312Reputation: 3312Reputation: 3312
Linux has a command which does just that (output column order is reversed from your example).

See...

Code:
man uniq
 
1 members found this post helpful.
Old 01-28-2017, 03:02 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 18,493

Rep: Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099Reputation: 3099
Associative array - bash, awk, perl, ...
 
Old 01-28-2017, 05:34 AM   #4
hoi
LQ Newbie
 
Registered: Jun 2013
Posts: 29

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
Linux has a command which does just that (output column order is reversed from your example).

See...

Code:
man uniq
Thank you very much. 'uniq -c' command solved it.
 
Old 01-28-2017, 05:42 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,769

Rep: Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052Reputation: 3052
Remember to mark the question as SOLVED once you ave a solution.
 
  


Reply

Tags
awk, bash scripting, grep, sed bash, shell script


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
print the number of occurrence of a pattern in multiple files count greater than 10 Vthimmap Linux - Newbie 6 07-06-2016 04:05 AM
Help with Perl to count number of matches in one column based on values in another captainentropy Programming 16 12-19-2013 03:12 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
Warning: [fnn_insert] Column count doesn't match value count at row 1 in bondoq Programming 2 09-27-2011 05:11 PM
sed / awk command to print line number as column? johnpaulodonnell Linux - Newbie 2 01-22-2007 08:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:28 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration