I type mosquitto_sub -d -t +/#
from the Ubuntu terminal to access the MQTT stream.
However I would like to see only a specific set of data from the MQTT stream. I've added | grep -v PING
so everything still be printed except for lines with PING in them but that didn't work.
I've tried | grep -A1 PUBLISH
so I can see lines from the MQTT with PUBLISH in them, nothing changed: I just get the whole MQTT stream nothing gets filtered out.
How can I see the certain thing that I want to see from an MQTT stream? Alternatively; how can I filter certain things out of the MQTT stream or how can I extract data from the MQTT stream?
My input from the ubuntu terminal is as follows $ mosquitto_sub -d -t +/#
and I've tried $ mosquitto_sub -d -t +/# | grep -v PING
and $ mosquitto_sub -d -t +/# | grep -A1 PUBLISH
but it just streams everything, doesn't grep anything. The output is as follows:
ed@agharta:~$ mosquitto_sub -d -t +/#
Received CONNACK
Received SUBACK
Subscribed (mid: 1): 0
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Sending PINGREQ
Received PINGRESP
Received PUBLISH (d0, q0, r0, m0, 'm/jsyd/TEST/001/d/status', ... (34 bytes))
Sending PINGREQ
Received PINGRESP
Received PUBLISH (d0, q0, r0, m0, 'm/jsyd/TEST/001/d/SVlts', ... (28 bytes))
Sending PINGREQ
Received PINGRESP
For example how can I only see the PUBLISH from the live stream and not the PINGs?
sed -n '/Subscribed/p' stream
– jasonwryan Feb 24 '15 at 03:13sed -n '/PATTERN/p' file
; I'm not too sure how to filter out specific words like "PING" and what the/PATTERN/
andfile
refer to; Simply put I just don't get it from reading it. – 3kstc Feb 24 '15 at 03:39sed -n '/PUBLISH/p' stream
however what does thestream
component do? – 3kstc Feb 24 '15 at 04:03sed -n '/PUBLISH/p' stream
what does thestream
component do? – 3kstc Feb 24 '15 at 04:48grep
doesn't operate onstderr
. Apparentlymosquitto_sub
logs tostderr
so (withbash
) you could try something likemosquitto_sub -d -t +/# 2> >(grep PUBLISH)
. For more details & options read the answers here. – don_crissti Feb 24 '15 at 12:42[what does this value mean]>[what does this space do?]>(grep [grepped keyword])
Additionally if I wanted to grep two or more keywords, how would I do it? – 3kstc Feb 24 '15 at 22:04