I wanted to write a grep function to show me all listening ports on my host.

I know how to do it by using the -i function in grep :

netstat -a |egrep -i 'listen'

But now I wanted to write it in regex :

netstat -a |egrep 'm/listen/i'

I thought : m because netstat outputs multiple lines and i because it is LISTEN, so I wanted case insensivety.

However this does not give any output. What am I doing wrong ?

link|improve this question

feedback

2 Answers

up vote 1 down vote accepted

You could try perl instead:

netstat -an | perl -n -e 'print m/listen/i'

I like the netstat solution. 1 Command done and dusted.

link|improve this answer
this is where I went wrong, thank you :) – Lucas Kauffman Aug 6 '11 at 12:59
feedback

You can show all listening ports with:

netstat --protocol=ip -nlp

About your command, grep works line by line. Where did you read this syntax, it seems belong to sed.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.