Bill Akins wrote:
> Hi!
> 
> I would like to grab the first column (variable width) of data in each
> line that will be returned from an external command.
> I tried @PSARRAY = `command | grep bf1`; and got just the lines with
> data I wanted.  The returned data looks like this:
> 
> EHCFS001   Booted     Down  bf1/p20   Windows/MU    Yes,Opt,0 12:55:29
> VMDFS      Booted     Up    bf1/p14   VM25AS21e16/MU Yes,Opt,0
> 12:52:12 ORA_1      Booted     Up    bf1/p18   VM25AS21e16/MU
> Yes,Opt,0 12:56:25 ps3        Booted     Up    bf1/p3    custom/MU   
> Yes,Opt,0 12:51:56 ps4        Booted     Up    bf1/p4    custom/MU   
> Yes,Opt,0 12:51:42 ps5        Booted     Up    bf1/p5    custom/MU   
> Yes,Opt,0 12:51:22 
> 
> I need to capture just EHCFS001, VMDFS, ORA_1, PS3, PS4 and PS5  in a
> var, array, hash, whatever and I don't care about any of the
> other data.
>  A variable would be preferable over array, I think.
> 
> I then tried @PSARRAY = `command | grep bf1 | awk -F " " '{print $1}'`
> but got the same exact results.  Anyone know why it didn't
> like the awk
> command or just decided to ignore it?

Variables are expanded in backticks, so you need to protect the $ on $1, or
use qx'' around your command (but then you have to protect the single quotes

But there's no need for the awk or grep, since perl has functions to handle
that kind of thing. Try something like:

   @PSARRAY = map +(split)[0], grep /bf1/, `command`;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to