Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • This worked fine. But fifo is closing after write to it. Is this expected behavior? I solved this with grepping fifo in a infinite while loop. But this is not working if I write to pipe with continious stream. For example: I have a shell script printnumbers.sh that looping infinite and printing 1,2,3,... to stdout each second. I am running ./printnumbers.sh > myfifo in one terminal, and in another terminal: while true; do grep -f myfifo numbers.txt | awk '{print $2; system("")}' done This printing to stdout when I stop print to fifo. Commented Dec 4, 2016 at 18:12
  • @mesuutt When the last writer on a pipe closes the pipe, readers get an end-of-file indication. I don't understand the rest of your comment. What are you trying to achieve? As I explain in my answer, grep reads the patterns before it starts processing the text to search. Do you want to search the data again each time a new pattern comes on the pipe? If so you will need to call grep (or awk) in a loop, since it has to read the data again and again each time. Commented Dec 4, 2016 at 18:34
  • Yes I want to search the data again each time a new pattern comes to pipe. Also I read from pipe within a loop. I have a bash script file printnumbers.sh that print numbers each second in infinite loop. Your solution works if I write to pipe as echo 1 > myfifo and print one to stdout but if I write to pipe numbers as: ./printnumbers.sh > myfifo not printing anything to stdout due to stop the ./printnumbers.sh > myfifo. gist.github.com/mesuutt/92e1d6286c442b2003fe2c67d2133d7b Commented Dec 4, 2016 at 19:03