Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting grep output to file

Tags:

bash

shell

If I execute

$ java -jar selenium-server.jar 2>&1 | grep "jetty.Server" 

I get, after a while, the output I expect:

$ 16:30:24.881 INFO - Started org.openqa.jetty.jetty.Server@6b0a2d64

But I i try to redirect grep output to a file, it doesn't write a thing

$ java -jar selenium-server.jar 2>&1 | grep "jetty.Server" > /tmp/ebook_selenium

Any idea why? Thanks

like image 992
pistacchio Avatar asked Nov 20 '25 04:11

pistacchio


1 Answers

We found that grep flushes its output when it writes to stdout but not to a file.

grep --line-buffered will force grep to output each line as it's processed.

like image 149
Adam Liss Avatar answered Nov 21 '25 17:11

Adam Liss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!