This question is NOT related to this as I don't want to redirect the output to more than one process. Instead, I want to pipe an output twice like you'd normally do, like this:
$ echo "piping twice" | cut -d 'p' -f 3 | cut -d ' ' -f 1
ing
This works as expected!
However, trying the same with tail -f
fails:
$ echo "piping twice" > somefile
# The first test passes:
$ tail -f somefile | cut -d 'p' -f 3
ing twice
# The second test shows nothing:
$ tail -f somefile | cut -d 'p' -f 3 | cut -d ' ' -f 1
I'm using tail as a reproducible example, but I'm actually trying to parse the progress output of youtube-dl
, and more than one piping always results in blank lines.
Am I doing something wrong?
Thank you.
This will work:
tail -f somefile | stdbuf -oL cut -d 'p' -f 3| cut -d ' ' -f 1
As most Linux programs will use line buffering if stdout
is connecting to a TTY and full buffering otherwise. You can use stdbuf
to force line buffering.