I am using dbus-monitor command to see every Dbus signal, the command is an infinite loop, so I am using awk with it to grep for a specific pattern.
I can get the first match and exit using:
dbus-monitor --system | awk '/<pattern>/ {print $2; exit}'
But, my system is going to a list of states for example x1 -> x2 -> x3
I want to use awk to get the first 3 signals of a given pattern and print them.
For example, when I start the system, x1 is sent and I can detect it with the first awk command, but when I run it again, I get x3, because x2 is already sent I did not catch it in time.
How can I change awk to use for example a counter and get me the first n matches?
Thanks.