On finished input (like a file) we can do that:

cat file | grep -o memory=[3-9] | sort -u

But sort won't work with a stream:

tail -f server.log | grep -o memory=[3-9] | sort -u

server.log can be an infinite stream (a real time log). Above command can last hours.

how can I aggregate results adding another tool into the pipe, or making somehow that sort will work?


what is the alternative, instead of grep, to have grepping there but also passing the argument into next step - next tool of the pipe. I am not sure if pipe will allow that, at all.

maybe the second part of pipe must be a combined one (like something doing grep+sort at once)

I am only interested with the command-line approach to that.

It could be something like watch, but updating the previous result.

On example: Instead of seeing a plenty of lines like:


I want to see just:


The above output is simplified, I wanted to highlight the aggregation of such output is my main problem.


the working solution is:

$ tail -f infinite_server.log | grep -o memory=[3-9] > output &


$ watch "cat output | sort -u"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.