![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Sort file alphabetically AND numerically | mrodrig | UNIX for Dummies Questions & Answers | 2 | 05-19-2008 10:46 AM |
| Sort a file line by line alphabetically | H2OBoodle | Shell Programming and Scripting | 11 | 02-11-2008 07:27 AM |
| How to sort decimal values in bash | ahjiefreak | Shell Programming and Scripting | 1 | 01-21-2008 09:25 AM |
| finding specific values in a within a file | Gerry405 | UNIX for Dummies Questions & Answers | 3 | 11-21-2005 11:37 AM |
| How to Sort files based on predefined values.? | p_prathaban | Shell Programming and Scripting | 2 | 02-17-2004 11:39 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
How to sort alphabetically after finding values
I have a list of people in a usage log and need to print the names and phone numbers of people with over 500 logins. I'd also like to display these names alphabetically.
I have their total logins set to a variable named total. So far, I have very little in my awk script to do this: FS=":" {if ( total > 500 ) print $1, $2} ($1 being both first and last name, $2 being phone number) There is more to the script than this, but above is the relevant portion. This only prints one of their names unfortunately, even though my data file clearly has others with totals > 500. Any advice or pointers here? Thanks! |
|
||||
|
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
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 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|