How set filter netstat -an | grep -P '\:'38''


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How set filter netstat -an | grep -P '\:'38''
# 1  
Old 09-02-2011
Network How set filter netstat -an | grep -P '\:'38''

Hi,

I can write sh script for Linux platform
I run:
Code:
netstat -an | grep -P '\:'38''| grep ESTABLISHED

but result:

Code:
[root@om910 install]# netstat -an | grep -P '\:'38''| grep ESTABLISHED
tcp        0      0 172.16.1.107:383            172.16.1.81:49981           ESTABLISHED
tcp        0      0 127.0.0.1:18170             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:10555             ESTABLISHED
tcp        0      0 127.0.0.1:10555             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:10329             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:10329             ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:47234             ESTABLISHED


It is not good, because i need to receive only 38 number. How provide it? Thanks

Last edited by pludi; 09-02-2011 at 01:45 PM..
# 2  
Old 09-02-2011
Might this help
Code:
$ netstat -an | grep ":38$" | grep ESTABLISHED

# 3  
Old 09-05-2011
hm...
but port 383 dosn't displayed
Code:
[root@om910 ~]# netstat -an | grep ":383$" | grep ESTABLISHED
[root@om910 ~]#


Last edited by Franklin52; 09-05-2011 at 06:31 AM.. Reason: Please use code tags for code and data samples, thank you
# 4  
Old 09-05-2011
Code:
 
$ nawk ' $4~/:38$/ || $5~/:38$/ {print $0}' test
tcp        0      0 127.0.0.1:10329             127.0.0.1:38               ESTABLISHED
tcp        0      0 127.0.0.1:38               127.0.0.1:47234             ESTABLISHED
tcp        0      0 127.0.0.1:38               127.0.0.1:47234             ESTABLISHED
 
$ cat test
tcp        0      0 172.16.1.107:383            172.16.1.81:49981           ESTABLISHED
tcp        0      0 127.0.0.1:18170             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:10555             ESTABLISHED
tcp        0      0 127.0.0.1:10555             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:10329             127.0.0.1:38               ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:10329             ESTABLISHED
tcp        0      0 127.0.0.1:38               127.0.0.1:47234             ESTABLISHED
tcp        0      0 127.0.0.1:38               127.0.0.1:47234             ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:47234             ESTABLISHED

so, in your case, you need the below command

Code:
 
netstat -an | nawk ' $4~/:38$/ || $5~/:38$/ {print $0}'

# 5  
Old 09-05-2011
Ok, but I don't have nawk, I run awk and follow:
Code:
[root@om910 ~]# netstat -an | awk ' $4~/:383$/ || $5~/:383$/ {print $0}'
tcp        0      0 0.0.0.0:383                 0.0.0.0:*                   LISTEN
tcp        0      0 172.16.1.107:383            172.16.1.81:49981           ESTABLISHED
tcp        0      0 127.0.0.1:18170             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:10555             ESTABLISHED
tcp        0      0 127.0.0.1:10555             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:10329             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:10329             ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:47234             ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:47236             ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:59280             ESTABLISHED
tcp        0      0 127.0.0.1:59290             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:59292             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:59280             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:59290             ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:59292             ESTABLISHED
tcp        0      0 172.16.1.107:55956          172.16.1.81:383             ESTABLISHED
tcp        0      0 172.16.1.107:55904          172.16.1.81:383             ESTABLISHED
tcp        0      0 127.0.0.1:47236             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:47234             127.0.0.1:383               ESTABLISHED
tcp        0      0 127.0.0.1:383               127.0.0.1:18170             ESTABLISHED
tcp        0      0 172.16.1.107:383            172.16.1.80:2106            ESTABLISHED
tcp        0      0 172.16.1.107:31380          172.16.1.80:383             ESTABLISHED
tcp        0      0 172.16.1.107:51517          172.16.1.80:383             ESTABLISHED
tcp        0      0 172.16.1.107:51523          172.16.1.80:383             ESTABLISHED
tcp        0      0 172.16.1.107:56111          172.16.1.80:383             ESTABLISHED


Last edited by Franklin52; 09-05-2011 at 06:31 AM.. Reason: Please use code tags for code and data samples, thank you
# 6  
Old 09-05-2011
Is this expected result ?

or you want only the ESTABLISHED ?

Code:
netstat -an | awk ' $4~/:383$/ || $5~/:383$/ {if($NF~/ESTABLISHED/)print $0}'

# 7  
Old 09-05-2011
Yes,
Can I provide expected result command grep or only awk?

Thank you!
Have a nice day!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need to filter the result set within 2 time frame

my sample file is like this $cat onefile 05/21/18 13:10:07 ABRT US1CPDAY Status 1 05/21/18 21:18:54 ABRT DailyBackup_VFFPRDAPENTL01 Status 6 05/21/18 21:26:24 ABRT DailyBackup_VFFPRDAPENTL02 Status 6 05/21/18 21:57:36 ABRT DailyBackup_vm-ea1ffpreng01 Status 6... (7 Replies)
Discussion started by: gotamp
7 Replies

2. AIX

How to grep PID and program name from netstat in AIX?

Hi All, I am using netstat on AIX to grep info on all open connections. However, unlike on Linux(Centos), I do not get the PID and program name using netstat on AIX. I need this info to be clubbed along with the information retrieved using netstat version of AIX. Is there a way this can be... (1 Reply)
Discussion started by: Vipin Batra
1 Replies

3. Shell Programming and Scripting

Grep regex filter

Hi, How can I run the grep search in a script to only include compute, not bigcomputer in following search input? " properties = local compute" " properties = local bigcompute" Thank you. -j (6 Replies)
Discussion started by: hce
6 Replies

4. Shell Programming and Scripting

awk : Filter a set of data to parse header line and last field of multiple same match.

Hi Experts, I have a data with multiple entry , I want to filter PKG= & the last column "00060110" or "00088150" in the output file: ############################################################################################### PKG= P8SDB :: VGS = vgP8SOra vgP8SDB1 vgP8S001... (5 Replies)
Discussion started by: rveri
5 Replies

5. Shell Programming and Scripting

netstat grep regex suspend script help

Hi I am trying to create a suspend script which will suspend the system only if it cant find port 9982 four or more times OR 192.168.0.:microsoft-ds ESTABLISHED in the output of netstat -t. I am struggling with the 9982 bit, googling etc I came up with if netstat -t|grep -P "(9982){4,}" ... (15 Replies)
Discussion started by: bilboNIX
15 Replies

6. Shell Programming and Scripting

awk script to filter the numbers which are around the set value

Hi All, I have one sensor output(over the same) for a set value of 20. Time(in Sec), Data 1, 16 2, 20 3, 24 4, 22 5, 21 6, 20 7, 19.5 8, 20 9, 20.5 10, 20 11, 20 12, 19.5 Here we can see like after 5 sec of time the data value reaches to 20+-0.5 range. So I... (7 Replies)
Discussion started by: ks_reddy
7 Replies

7. UNIX for Dummies Questions & Answers

Command line / script option to filter a data set by values of one column

Hi all! I have a data set in this tab separated format : Label, Value1, Value2 An instance is "data.txt" : 0 1 1 -1 2 3 0 2 2 I would like to parse this data set and generate two files, one that has only data with the label 0 and the other with label -1, so my outputs should be, for... (1 Reply)
Discussion started by: gnat01
1 Replies

8. Shell Programming and Scripting

Filter on a grep

I am attempting to figure out how to only capture part of a grep command I am doing. So far no luck. When I execute.... leviathan:/gfs/home/tivoli>ps -ef | /usr/ucb/ps -auxww | grep nco_p_syslog The results are.... tivoli 10185 0.0 0.0 5888 5168 ? S Oct 23 0:26... (2 Replies)
Discussion started by: LRoberts
2 Replies

9. Programming

Libpcap: Set a filter. (C)

Hi I'm reading about the libpcap documentation. I see that with the function: pcap_setfilter ( pcap_t *p, struct bpf_program *fp) we can choose to take one packet instead another. I read that the struct bpf_program allow us to create a packet filter , ....so if I want just sample some... (2 Replies)
Discussion started by: Dedalus
2 Replies

10. UNIX for Dummies Questions & Answers

need help on netstat -na |grep

Hi, I use the following cmd to view list of clients connected to my HPUX server netstat -na |grep Can anyone help me with the UNIX cmds to find list of clients connected to my HPUX server including idle time. Any help will be highly appreciated. Thanks MH (2 Replies)
Discussion started by: mhbd
2 Replies
Login or Register to Ask a Question