[comp.unix.questions] Perl finding marvin

merlyn@iwarp.intel.com (Randal Schwartz) (12/13/89)

In article <1507@rodan.acs.syr.edu>, jdpeek@rodan (Jerry Peek) writes:
| I'm no expert, but I think "sed" is great -- fast and flexible, just cryptic.
| Maybe Randall and I should have a perl-vs.-sed showdown. :-) :-)
              ^
Well, I was going to be silent, but since you spelled my name funny
(didn't someone else do this last time? :-)...

Sed is fine for this task, but just for a comparison, if you want the
second load average on the line with "marvin", it'd be something like:

set load=`ruptime | perl -ne 'print "$1\n" if /^marvin\s.*,\s*(.*),.*/;'`

I'm presuming that the definition of the desired field is something
like "the sequence of characters between the next-to-last comma and
the last comma, discarding leading whitespace (if any)".  That's what
that regex finds.  (As you parse it, remember that .* matches as
_many_ characters as possible.)

There's your one minute Perl lesson for today, kids.

Just another Perl hacker,
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III  |
| merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/