[Tutor] Re: what do I use for this?

Lee Harr missive at hotmail.com
Mon Mar 15 19:26:49 EST 2004


>I want to make a script that asks for a port number and returns its 
>meaning.
>Since there are a few thousand ports, I just want to start with common 
>ones.
>What would I use in this program? An array(s)?


I usually just use grep ...


$ egrep "\b80/" /etc/services
http             80/tcp    www www-http         #World Wide Web HTTP
http             80/udp    www www-http         #World Wide Web HTTP
$ egrep "\b135/" /etc/services
loc-srv         135/tcp    epmap        #Location Service
loc-srv         135/udp    epmap        #Location Service


the \b means "word boundary" so that it does not match 180.
the / matches the slash before the tcp or udp so that it does
  not match 800, 805, etc.

_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail




More information about the Tutor mailing list