cancel
Showing results for 
Search instead for 
Did you mean: 

shell script

SOLVED
Go to solution
file system
Frequent Advisor

shell script

Hi all.
can I get the proper data from awk?
I'm going to get the 80 port connected from client
netstat -na|grep 80|awk '{print $5}'
the output is
as below
211.230.217.114:13098
221.159.231.39:11257
211.230.217.114:13534
211.230.217.114:13200
222.98.234.60:7370
211.230.217.114:14410
211.230.217.114:13995
222.98.234.60:7195
211.230.217.114:14629
211.237.50.75:80
211.237.50.75:80
211.237.50.75:80
211.237.50.75:80
127.0.0.1:80
127.0.0.1:80
127.0.0.1:80
127.0.0.1:9001
59.4.203.206:5514
211.229.236.56:16304
211.221.23.87:8704
211.221.23.87:7950
211.221.23.87:8250
211.221.23.87:8509
211.221.23.87:8747
211.229.236.56:15751
218.144.122.134:5413
211.221.23.87:9262
211.221.23.87:8281
211.229.236.56:2543
211.221.23.87:8306
211.229.236.56:16323
218.144.122.134:5533
211.221.23.87:8338
222.232.158.138:14598
211.229.236.56:2096
218.144.122.134:5519
218.144.122.134:5506
211.221.23.87:8628
211.237.50.102:80
211.237.50.102:80
211.237.50.102:80
211.221.23.87:8144
211.221.23.87:8668
211.229.236.56:2670
211.221.23.87:8901
211.221.23.87:8649
211.221.23.87:8652
211.221.23.87:8436
211.229.236.56:15951
211.229.236.56:2121
10.10.10.86:1521
211.221.23.87:8681
211.221.23.87:8684
211.230.217.114:14027
220.119.104.171:15816
211.216.214.37:4796
211.230.217.114:13708
211.230.217.114:14498
211.230.217.114:14759
211.230.217.114:14263
211.216.214.37:6944
220.119.104.171:15705
211.230.217.114:13412
211.230.217.114:14184
211.230.217.114:13676
211.230.217.114:13423
211.230.217.114:13937
211.230.217.114:14101
222.98.234.60:7293
211.237.50.80:3385
125.133.237.131:2819
61.78.62.12:4677
61.78.62.12:4683
125.133.237.131:2626

I have 2 problems
1. how to get the uniq ip from output except for duplicated ip
2. how to get the separator ":" from the output
so first field is IP and second field is port

I need your help..!!!
1 REPLY
Ivan Ferreira
Honored Contributor
Solution

Re: shell script

>> how to get the separator ":" from the output

| tr ":" " "

>> how to get the uniq ip from output except for duplicated ip

| sort -u -k 1,1

So it could be:

netstat -n | awk '{ print $5}'| grep ":80 " | tr ":" " " | sort -u -k 1,1
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?