0

I have some usb device (connected to my mac) that produces text output. I use cu with tee to redirect the output to some file:

sudo cu --speed 57600 --line /dev/cu.usbmodem54240287031 | tee cu.log

cu.log looks like:

Sensor data reading ...
SCD30 CO2:  1121
SCD30 Temp: 24.30
SCD30 Humi: 32.59
SGP40 VOC: 30570
SPS30 PM25: 3.91

...

Now I want to put that through a pipe using tail, like this

tail -f cu.log | grep CO2

This works fine. But if I append another step to the pipe it just stops to produce output:

tail -f cu.log | grep CO2| awk '{print $3}'

And I don't know why and how to solve the problem. Can anyone help?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • 1
    I suggest to use `grep` and `awk` versions with options for line buffering on output. – Cyrus Dec 14 '22 at 14:55
  • 1
    See [BashFAQ #9](https://mywiki.wooledge.org/BashFAQ/009). There's output; it just doesn't get flushed immediately. – Charles Duffy Dec 14 '22 at 16:47
  • 1
    BTW, as a note unrelated to the immediate buffering problem, it's _never_ necessary to run `grep | awk`. Just run `tail -f cu.log | awk '/CO2/ { print $3 }'`, making the pattern match a condition of the awk code. – Charles Duffy Dec 14 '22 at 16:49

0 Answers0