Register
It is currently Fri Nov 28, 2014 9:42 am

Sort and remove uniques


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Thu May 20, 2010 11:53 am   

Joined: Thu May 20, 2010 11:50 am
Posts: 2
I am not sure if this is possible with bash, if it is not, I have to find another way to sort it out.

I have a file, for example IPs.txt. In the file I have several IP addresses listed.
If the IP is listed in the file for 5 or more times, I want to hold in, otherwise I want to delete the IP address. So every IP which is not listed >5 must be deleted.

So at the end I will end with a file with only with the IP's which were listed 5 or more times.


Top
 Profile  
 PostPosted: Thu May 20, 2010 3:07 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
The first thing to do is to run this:
Code:
sort | uniq -c | sort -n

The rest is easy B-)


Top
 Profile  
 PostPosted: Sun May 23, 2010 1:43 am   

Joined: Thu May 20, 2010 11:50 am
Posts: 2
I found a really easy way, for example to list only the IP's which are duplicate for more than 5 times:
Code:
awk 'seen[$0]++ == 5' IPs.txt


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP