Answer the question
In order to leave comments, you need to log in
grep - how to make an exact match?
There is data from qm list:
100 srv1 running 16384 100.00 965
101 srv2 running 12314 100.00 900
1000 srv3 running 2048 100.00 85
1001 srv4 running 2048 100.00 35
10000 srv4 running 2048 100.00 480
sudo qm list | grep 100 | awk '{print $3}'
Answer the question
In order to leave comments, you need to log in
Why is grep here? awk is very good at comparing, and, unlike grep, it can work with individual fields, and not just with the whole line.
sudo qm list | awk '{ if ($1 == 100) print $3}'
grep just finds 100 lines elsewhere.
Write a regular expression that will look for the first 100, such as the beginning of a string, possibly spaces, and 100:
sudo qm list | grep -P '^[ ]*100' | awk '{print $3}'
sudo qm list | grep -P '100[^.]' | awk '{print $3}'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question