Score:0

Pipe to grep to directional operator (to file)

za flag

What works: any of these three:

ping 8.8.8.8 | grep 3  // this will steadily output any ping with the number 3 somewhere in the line to the terminal
ping 8.8.8.8 > fileping //this will silently add all the ping output to the file 'fileping'
tee filetee < <(ping 8.8.8.8) // this will show the pings in terminal AND add them to the file

What does not work: these two combinations of the above:

ping 8.8.8.8 | grep 3 > fileping  // this will run, but silent, and the file stays empty
tee filetee < <(grep 3 < <(ping 8.8.8.8)) // will also run silent, leave empty file

What it is supposed to do: Take the output of ping 8.8.8.8, grep it, and then add the results to a file

Following the recommendation in comment of steeldriver i tried

ping 8.8.8.8 | grep --line-buffered 3 | tee fileping  // this will run, output the filtered pings to terminal, and fill the file.
ping 8.8.8.8 | grep --line-buffered 3 > fileping  // this will run, silently, and fill the file.

So the actual task works. Yay! Will delve into --line-buffered to find out why

this is mostly for understanding the underlying principles, so an answer explaining why it does not work is probably just as good as a command that uses different principles than '|' and '<'

hr flag
Try adding the `--line-buffered` option to your grep command
hr flag
... see also [grep - Output not redirecting to file](https://askubuntu.com/questions/280443/output-not-redirecting-to-file)
Score:1
za flag

So turns out grep is buffering if the output is connected to a pipe ('|') or redirected ('>') to a file. Depending on the (OS-dependent) size of the buffer, it might for instance accrue 4096 bytes of output before giving it out.

In my examples above the accretion of data was too slow for me to notice this, i shut down the process before the buffer was full, resulting in loss of the data.

Adding --line-buffered to the grep command will ensure it flushes as soon as it encounters a newline character. Alternatively, one can prefix the command with stdbuf -oL (also does line buffering, but is not specific to grep) or stdbuf -o0 (will reduce buffer to 0, forcing flush, also works on more than just grep)

so instead of grep, use grep --line-buffered or stdbuf -o0 grep

for general, in depth, info on buffers in stdio : http://www.pixelbeat.org/programming/stdio_buffering/

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.