The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-27-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Sounds like the problem would be in other parts of the logic. Is total calculated once for the whole file, and you run it again and again for each user, or how do you end up with that total?

A common technique is to keep an array of totals where the keys are the users, so you only have to run over the file once.

Code:
awk -F : '{ if (++total[$1] > 500) print $1, $2 }' file
(This will print multiple times, once for each record after the total is exceeded. Figuring out how to avoid that is left as an exercise.)

Once you get it to print what you want, just pipe that output to sort.

Last edited by era; 04-27-2008 at 05:58 PM.. Reason: Code example