Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!brutus.cs.uiuc.edu!apple!oliveb!orc!mipos3!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Perl finding marvin (was Re: using sed) Message-ID: <5348@omepd.UUCP> Date: 13 Dec 89 15:48:49 GMT References: <14404@eerie.acsu.Buffalo.EDU> <1507@rodan.acs.syr.edu> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 26 In-reply-to: jdpeek@rodan.acs.syr.edu (Jerry Peek) 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!" ==/