Skip to content
Advertisement

How to grep a particular pattern

I am trying to get a particular pattern, but i get the result for all possible solutions

JavaScript

I did try all the solutions available here

JavaScript

How do I get only the PID: 467?

Advertisement

Answer

If your goal is to grep only for “lubuntu”, not “lubuntu-somethingelse”, then you can add a space afterwards:

JavaScript

Or without the extra commands:

JavaScript

Edit: If you need something reliable and general-purpose, not for your own script, then parsing the commandline is always going to be a bad idea. There are too many things that can go wrong. Since you’re using libvirt for managing the VMs, have a look at scripting virsh instead.

Edit2: So you can either get the pid by getting the pid attribute from the domstatus node in /var/run/libvirt/qemu/lubuntu.xml, or get the same information via the virsh desc --live lubuntu.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement