I would like to have some help writing a script (which should work on FreeBSD where I have sh as default) that should grab a precise string when I do a ps ax | grep bhyve
command from the terminal. For example :
# ps ax | grep bhyve
43137 - Is 0:00.00 bhyve: system.pwd (bhyve)
43138 - Is 0:00.00 bhyve: system.grp (bhyve)
43132 0 IC 2:06.86 bhyve: vm0:18 (bhyve)
43234 1 D+ 0:00.00 grep bhyve (csh)
when I do :
ps ax | awk '/bhyve: vm/{print $6}'
it gives :
vm0:18
/bhyve:
when I do :
ps ax | awk '/bhyve: [vm]/{print $6}'
it gives :
vm0:18
but they are both wrong. The result should be : 0:18
thanks.
sed
to do the last bit.ps axo time,command
will get you exactly the columns you want, in the order you want them in. but I'd proably write it in C if I used the program a lot