I have a little Raspberry Pi monitoring things like temperature, wind and pressure. Now our dear russians have started to tamper with GPS in my neighbourhood and I saw that our authorities where rather slow to react. I have an old GPS pl2303 GPS dongle which I think could be good to keep a timely check on local GPS behaviour. My problem is the following:
Using the NMEA-stream from gpsd and gpspipe I try to extract the coordinates with awk:
gpspipe -r |grep GPGGA
gives me
...... $GPGGA,225842.00,5919.2601,N,01758.1669,E,1,06,2.00,19.55,M,24.163,M,,*5 .....
but
gpspipe -r |grep GPGGA|awk -F, '{ print $3 } { print $5 }'
gives me nothing. If I, however, save the output from gpspipe -r to a file g
cat g|grep GPGGA|awk -F, '{ print $3 } { print $5 }'
gives me ... 5919.2689 01758.1838 ... which is what I want. Why doesn't awk produce the desired output when directly fed with the NMEA stream? What have I missed? H
Probably you are not waiting long enough.
If your
grephas a--line-bufferedoption that should help:Or if your system has
stdbufyou can try:(or
... stdbuf -o0 ...)When using
awk,grepis not required:explanation
I am guessing that
gpspipe -rproduces output continuously until stopped. If that is the case, your problem is probably that whengrepoutput is fed into a pipe, it is buffered. Until the buffer is full,awkdoes not receive any input.You can get an idea with: