1

How can I split stdout to several parallel processes in one reading step? grep/sed is only an example

file AAA
AAA
BBB
CCC
DDD
EEE
FFF
cmd1 ($ cat AAA ) -----+---- cmd2 ( eg. grep "A" > fileA.txt ) ----->>
                       |
                       +---- cmd3 ( eg. sed -n -e '/^A/,/^D/p' > fileB.txt--->>
                       |
                       +---- cmd4 ( eg. grep "C" > fileC.txt ) ---->>
                       |
                       +---- cmd5 ( eg. grep "F" > fileF.txt ) ---->>
Worthwelle
  • 4,816
paf1
  • 11

1 Answers1

0

paf1's comment is the minimal solution.

This is longer, but it gives you the control of GNU Parallel:

cat AAA |
  parallel --pipe --tee ::: 'grep "A" > fileA.txt' "sed -n -e '/^A/,/^D/p' > fileB.txt" 'grep "C" > fileC.txt' 'grep "F" > fileF.txt'

So you could do something like:

cat AAA |
  parallel --pipe --tee grep {} '>' file{}.txt ::: A B C D E

or:

cat AAA |
  parallel --pipe --tee --tag grep {} ::: A B C D E

If you are running a lot more than 3 receivers of the input, then this is often easier to read.

Ole Tange
  • 5,099