Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk Question (Simple)

Status
Not open for further replies.

itrylinuxandlike

Programmer
Jun 5, 2006
1
US
Hello Everyone,

I have a .txt file with usernames. The file reads:

user1
user1
user1
user1
user2
user2
user2
user3
user3
user3
user3

And so on. With Awk, how do I select only the user# that are shown 4 times? So in another file it would read:
user1
user1
user1
user1
user3
user3
user3
user3

THANK YOU!!!!
 
awk '{++a[$1]}END{for(u in a)if(a==4)for(i=0;i<4;++i)print u}' users.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
or rather

uniq -c filename | awk '$1 == 4 {for (i=1; i<5; i++) print $2}'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top