我需要解压缩一个非常大的文件(100GB+(并使其由两个并行线程处理。问题是我想使用 STDIN/STDOUT 同时将未压缩的内容馈送到两个线程
bzip2 north-america-latest.osm.bz2 |
osmosis --read-xml file=- # get first thread
--tf accept-ways highway=motorway
outPipe.0=motorway
--fast-read-xml file=- # here another thread
--tf accept-nodes place=*
outPipe.0=places
--merge inPipe.0=motorway inPipe.1=places
语法可能不是那么透明,但想法是两个线程从相同的标准输入读取,并且基本上窃取彼此的数据。
不知何故,我需要让每个线程都有自己的 STDIN(或另一个临时内存流(并在它们之间拆分 bzip2 的输出。
您可以使用 tee 将输出拆分为多个进程
bzip2 north-america-latest.osm.bz2 | tee >(command1) | command2
您可以拥有任意数量的命令。
bzip2 north-america-latest.osm.bz2 | tee >(command1) >(command2) >(command3) | command4
管道后面的命令是可选的。如果省略,它将继续转到标准输出。