0

I have a command that I want to run from a shell script which is:

vim-cmd vmsvc/getallvms

I would like to turn the output of this command into a variable which is:

60 abc-trunk [xxxxx] abc-trunk/abc-trunk.vmx rhel6_64Guest vmx-10 xxxx OEM, CentOS 6.7, latest trunk install from xxxx.yyyyyy.com

I would like to turn the output into a variable and trim everything out of the variable so all I am left with is a variable that will read "abc-trunk"

1 Answers1

0

Your can do this using PHP,

$result= "60 abc-trunk [xxxxx] abc-trunk/abc-trunk.vmx rhel6_64Guest vmx-10 xxxx OEM, CentOS 6.7, latest trunk install from xxxx.yyyyyy.com";
$lines = explode("/n",$result);     
foreach($lines as $key=>$val)
            {
                $val = preg_replace('/\s+/', '|', $val);
                $l = explode("|", $val);
                if($l['1'] <> "")
                {
                    $vm=$l['1'];
                }
            }
print_r($vm);

This will Output "abc-trunk".

Edit the code inside foreach loop as per your need.