The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Awk to print distinct col values anduzzi Shell Programming and Scripting 22 08-18-2008 06:09 PM
counts the number of distinct words Net-Man Shell Programming and Scripting 14 08-18-2008 03:26 PM
how to pick distinct records.......... ss4u UNIX for Dummies Questions & Answers 3 01-04-2007 02:39 AM
select distinct row from a file merry susana UNIX for Dummies Questions & Answers 7 05-03-2005 07:54 AM
Comparing a distinct value in 1 list with another list manualvin Shell Programming and Scripting 6 06-22-2004 07:42 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-16-2008
jingi1234 jingi1234 is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 48
Count the distinct list of ids

Hello guys,

I have a file in the following format(each line seperated by TAB):
=========
Filename id
Filename id1
Filename id
Filename1 id7
Filename1 id7
Filename2 id1
Filename2 id1
Filename2 id3
Filename3 id2
Filename3 id4
Filename3 id4
Filename3 id6
=========
I would like to get the count of distinct ids from each file:
Output should like :
Filename 2
Filename1 1
Filename2 2
Filename3 3

Can some please help me?
  #2 (permalink)  
Old 10-16-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,805
Your example is confusing for me. Filename 1 in your example output should be Filename 2.

Please try again.
  #3 (permalink)  
Old 10-24-2008
loveno loveno is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 5
cat <filename> | sort -u | awk '{a[$1]++} END{for (f in a) print f, a[f]}'

this command works for your question.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0