我在一个目录中有一些已排序的 gzip 文件。如何将其中一些组合成另一个已排序的 gzip 文件?现在我正在使用显式fifos。有没有办法在 bash 中做到这一点?我是一个 bash 菜鸟,所以请原谅我缺乏风格。
#!/bin/bash
# Invocation ./merge [files ... ]
# Turns an arbitrary set of sorted, gzipped files into a single sorted, gzipped file,
# printed to stdout. Redirect this script's output!
for f in $@
do
mkfifo $f.raw
gzcat $f > $f.raw &
# sort -C $f.raw
done
sort -mu *.raw | gzip -c # prints to stdout.
rm -f *.raw
我正在寻找将其转换为类似...
sort -mu <(gzcat $1) <(gzcat $2) <(gzcat $3) ... | gzip -9c # prints to stdout.
......但不知道如何。我是否需要一个循环将参数构建为字符串?有什么神奇的捷径吗?也许map gzcat $@
?
注意:每个文件都超过 10GB(解压后为 100GB)。我有一个 2TB 驱动器,所以这不是问题。此外,该程序必须在 O(n) 中运行,否则将变得不可行。