* FemmeFatale <[EMAIL PROTECTED]> [030206 17:40]:
> Thx CM.  Question:  what are regular expressions ?  And sed?  Heard of 
> it... but no clue what it is... I'll look it up later.  The "regular 
> expressions" has me stumped though mostly.

Regular expressions are REALLY fun.  I saw recently that someone said
that regular expressions are to strings what math is to numbers.

I do a lot in Perl, and it has very powerful regex capabilities.
There are similar but (usually) slightly less capable regexes in
many GNU utilities and languages, including egrep, sed, awk, PHP,
and many others.

Using a Perl example (something I'm working on right now), if one line
of output from this command:

netstat -pe

produces:

tcp  37088  0 ahau.localdomain:33148  ltc002:x11  ESTABLISHED  judy
73301

(that's all on one line), then we can use:

/^tcp\s+\d+\s+\d+\s+(\w+)\.\w+:\d+\s+(\w+):x11\s+ESTABLISHED\s+(\w+)/

and then we can print out the three pieces I'm interested in:

printf "%-9s  %-9s  %-9s\n", $1, $2, $3

to give me a listing of servers, LTSP workstations, and users.  This

ahau       ltc002     judy

is much easier to read than the original.

As another example, suppose you ask the user to confirm, and you want
to check for a positive response, like y or yes or yep or yeah or ok:

doaction() if /^(y|ye(s|p|ah)|ok)$/i;

Anyway, hope this gives you an idea.  Jeffrey E. F. Friedl's book,
Mastering Regular Expressions (O'Reilly) is a good reference, and
there are tutorials and such if you Google 'em.

-- 
Jan Wilson, SysAdmin     _/*];          [EMAIL PROTECTED]
Corozal Junior College   |  |:'  corozal.com corozal.bz
Corozal Town, Belize     |  /'  chetumal.com & linux.bz
Reg. Linux user #151611  |_/   Network, PHP, Perl, HTML


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to