Get Ips from a list file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get Ips from a list file
# 1  
Old 01-11-2012
Get Ips from a list file

Hi Everyone,

I typed a command:
Code:
awk '{ print $1}' $LOGFILE | sort  | uniq -c  | sort -nr > $DEST/a.txt

And I got file a.txt which show
Code:
 6 1.1.1.1
 3 2.2.2.2
 2 3.3.3.3
 1 4.4.4.4

Just now, I want to get exact ips which has first column > 5 to a file b.txt. In this situation, the result must have 1.1.1.1 in b.txt

Could someone help me ?


Thanks in advance


Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 01-12-2012 at 04:54 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 01-12-2012
try this..


Code:
awk '{a[$1]++;next}END{for (i in a){if(a[i]>5){print a[i],i}}}' $LOGFILE

# 3  
Old 01-12-2012
Code:
while read x y; do [ $x -gt 5 ] && echo "$x $y"; done < a.txt > b.txt

# 4  
Old 01-12-2012
@itkamaraj

Thanks guy but it doesn't work . I replaced by your code but nothing in b.txt
# 5  
Old 01-12-2012
redirect it to b.txt

Instead of using your code, use the below code and give the $LOGFILE as input file for awk

Code:
 
awk '{a[$1]++;next}END{for (i in a){if(a[i]>5){print a[i],i}}}' $LOGFILE  > b.txt

---------- Post updated at 09:59 AM ---------- Previous update was at 09:58 AM ----------

Code:
 
$ awk '{a[$1]++;next}END{for (i in a){if(a[i]>5){print a[i],i}}}' test.txt 
7 2.2.2.2
7 3.3.3.3

 
$ cat test.txt 
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
2.2.2.2
3.3.3.3
2.2.2.2
3.3.3.3
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4

This User Gave Thanks to itkamaraj For This Post:
# 6  
Old 01-12-2012
@itkamaraj

Thanks so much guy, got it..I got wrong input file =]]
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Get List of users+IPs

Hello! We have an AIX box (6.3), we are looking for a way to get list of logged in users and their IP. The issue we have is running who -ub shows hostname and we are wanting to get the ip. Any suggestions of ideas? Thanks in advance for any help! (4 Replies)
Discussion started by: entropy1980
4 Replies

2. Shell Programming and Scripting

Help with shell script - filter txt file full of ips

Hello again gentlemen. I would like to make a shell script to 'optimize' a plain text full of IPs. Let's suppose to have this text file: 1.192.63.253-1.192.63.253 1.0.234.46/32 1.1.128.0/17 1.116.0.0/14 1.177.1.157-1.177.1.157 1.23.22.19 1.192.61.0-1.192.61.99 8.6.6.6 I want to... (2 Replies)
Discussion started by: accolito
2 Replies

3. Solaris

Updating my Solaris 11 IPS

Hi experts, I have an X86 as my IPS server running ( uname -a SunOS 5.11 11.1 i86pc i386 i86pc). the IPS has the following package version: prdb01b:~# pkg list -fa entire NAME (PUBLISHER) VERSION IFO entire ... (0 Replies)
Discussion started by: afadaghi
0 Replies

4. IP Networking

Find out my gateway ips?

hi, i want to know how can i get my gateway ips in the network,what i want is the ip of my neighbors in subnet( computers that are directly connected to my computer via lan or wlan), how can i get these information? thanks in advance. (2 Replies)
Discussion started by: gongotar
2 Replies

5. Shell Programming and Scripting

Filter a list of IPs

Hello, I have a dump of IPs (around 2 million) and i need to filter out(delete) 37 IPs from this list. Here is a short list of IPs that i would need deleted 111.111.xxx.xxx 123.123.xxx.xxx 127.x.x.x 98.20.xx.xxx 10.135.xxx.xxx 11.105.xxx.xx 100.100.xxx.xxx 101.xxx.xx.xxx ... (11 Replies)
Discussion started by: senormarquez
11 Replies

6. Linux

Regex for plucking out IPs and CIDRs from text file?

Hello to the unix.com community. I have a mess of text. What I would like to do I pluck out IP addresses and CIDR notations only. I thought I would try something like this /usr/bin/grep -o '\{1,3\}\.\{1,3\}\.\{1,3\}\.\{1,3\}\\' /Path/To/File But there are a few problems wit this. ... (3 Replies)
Discussion started by: TroubleNow345
3 Replies

7. IP Networking

To add more than 500 ips

To add more than 500 ips Hi, I have a server, which has more than of 1000 ip address, but only 500 ip address are responding in the Server. Here below the error message received while restarting the named Code: Sep 22 00:25:00 ns2 named: creating IPv4 interface... (2 Replies)
Discussion started by: gsiva
2 Replies

8. Shell Programming and Scripting

List of IPs & database lookup

I am trying to feed a list of IP's to do lookups from a database. My script works only for the first IP but all subsequent IPs output as 'unknown'. #!/usr/bin/php -q <? $ip = file('ip.txt'); foreach ($ip as $ip_num => $ip) { echo $ip; $out=sprintf("%u", ip2long($ip)); ... (1 Reply)
Discussion started by: hazno
1 Replies

9. Shell Programming and Scripting

Eleminating Duplicate IPs from a text file

Hey Guys I need to eleminate duplicate IP's from a text file using bash.Any suggestions.Appreciate your help guys. --CoolKid (4 Replies)
Discussion started by: coolkid
4 Replies
Login or Register to Ask a Question