How to pipe and echo the result that is being processed?

5,229

There is a similar question en Stack Overflow:

https://stackoverflow.com/questions/670784/redirecting-bash-stdout-stderr-to-two-places

The idea is to use named pipes, in bash you can simply do:

command_that_writes_to_stdout | tee >(command_that_reads_from_stdin)

But in the general case, use mkfifo, for example:

mkfifo some_pipe
command_that_writes_to_stdout | tee some_pipe \
  & command_that_reads_from_stdin < some_pipe
rm some_pipe

(both examples are from the Stack Overflow answer)

Share:
5,229
uset631458
Author by

uset631458

Remote Software Engineer. Website development + Native Mobile (Unity / C#) Languages / skills (order of daily use): Python / Django JavaScript JavaScript / jQuery HTML C# Php Old loves: C - Pascal - C++ Strong skills: vim and ssh for remote development Professional websites: Django / Python (v3): www.cogofly.com Blog: https://olivierpons.fr/ (800 visits/day) Wordpress Very complex multilanguage admin plugin: www.krystallopolis.com My own Php high performance framework (v3): My latest - full rewrite - (v3): www.papdevis.fr v2: http://pretassur.fr http://groupe-synergies.fr v1: http://www.acarat.fr/ Personal websites: http://labyz.fr/ http://wipwip.com/ http://wogwog.com/ http://doonoo.com/

Updated on September 18, 2022

Comments

  • uset631458
    uset631458 almost 2 years

    I'd like to execute this command:

    find /apps/ -type f -print0 | grep -z log$ | xargs -0 grep 'this->aForm'
    

    And in parallel, I'd like to see which files are being processed.

    How to to this?

    • voretaq7
      voretaq7 almost 11 years
      @oliver While it's not a bad question I'm going to close this as off-topic as it really doesn't directly deal with system administration (general scripting questions are more appropriate on Unix & Linux). If you'd like to try for more answers I can migrate this, but it's useful here as a signpost pointing to the Stack Overflow question too...