75inchpianist
75inchpianist

Reputation: 4102

Send grepped tail output to netcat

I am trying to run the following command, and nothing is getting sent to netcat

tail -F file.txt | grep test | nc host 9999

If I remove the grep, the tail successfully is followed and sent to netcat.

If I just run the following, data comes back, so I know that data should be getting sent to the nc pipe:

tail -F file.txt | grep test

Any ideas?

UPDATE

I added the following to unbuffer the piped output and nothing goes through:

tail -F file.txt | stdbuf -o0 grep test | nc host 9999

When I turn on line buffering, output is cut off

tail -F file.txt | grep --line-buffered test | nc host 9999

Where

workid: ID:ITEST_HGR1-EMS12103.1A156BB6CEB1:10F76E5D

is sent as

workid: ID:ITEST_HGR1-EMS12103.1A156BB6CEB1:10F7 

Upvotes: 1

Views: 1019

Answers (1)

Adam B
Adam B

Reputation: 3833

You need to change the default buffering behavior of grep. If you're on a GNU grep, you can use grep --line-buffered, or try unbuffer.

Upvotes: 4

Related Questions