The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Output in my shell isn't showing properly. satyakide Shell Programming and Scripting 7 04-01-2008 07:05 AM
Help with showing the difference in two lines of input Kweekwom Shell Programming and Scripting 12 02-14-2008 04:16 PM
displaying/ counting lines aga Shell Programming and Scripting 2 08-08-2007 12:35 AM
word count showing wrong number of lines tselvanin UNIX for Dummies Questions & Answers 3 01-06-2004 08:33 PM
Counting lines and files jorge.ferreira UNIX for Dummies Questions & Answers 6 12-11-2003 08:24 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 08-02-2004
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Untested awk..

awk '{a[$1 FS $2]++}END{for(x in a)print x,a[x]}' infile > outfile
Reply With Quote
Forum Sponsor
  #9  
Old 08-02-2004
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Ha ha ...every time I see a thread like this I just wait for Ygor to respond..He's definitely one with Awk!
Reply With Quote
  #10  
Old 08-02-2004
Registered User
 

Join Date: Aug 2004
Posts: 11
YGOR your close to the result that i wanted

this is the output of your awk
YRLNCA11-SL1 DMT8a4 13

it should have been
YRLNCA11-SL1 DMT8a4 5 2
YRLNCA11-SL1 DMT8a4 6 11

the first 2 fields are still the same but the 2nd to the last is different - 5 and 6

5 appeared 2x
and 6 appeared 11x

almost there ... but I could still use that awk though..

THANKS
Reply With Quote
  #11  
Old 08-03-2004
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
You could probably change Ygor's awk to

awk '{a[$1 FS $2 FS $3]++}END{for(x in a)print x,a[x]}' infile > outfile

to use the first three fields as the index

Cheers
ZB
Reply With Quote
  #12  
Old 08-03-2004
Registered User
 

Join Date: Jul 2004
Location: Beirut
Posts: 25
awk not clear

Please can somebody explain the awk solution of ygor and zazzybob, i tried to play with it on my machine to make some sence of it but it is not clear yet...
i am an awk lover but still biginner.
Reply With Quote
  #13  
Old 08-03-2004
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
The awk program uses an associative array "a" to hold the count for each key. The key is the first 2 or 3 fields. At the end of the input file, loop thru the array and print each key with its count.

It's not mandatory to use awk, you could use shell utils, e.g....

$ sort infile | cut -d' ' -f-3 | uniq -c | while read A B C D; do echo $B $C $D $A; done
ALBQNMMA-SL1 DMT8a4 12 1
ALBQNMMA-SL1 DMT8a4 3 4
FUTNCA01-SL1 DMT8a4 5 6
FUTNCA01-SL1 DMT8a4 6 3
Reply With Quote
  #14  
Old 08-03-2004
Registered User
 

Join Date: Aug 2004
Posts: 11
THANK YOU TO EVERYBODY THAT HELPED -- LEARNED A LOT!!!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 02:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0