如果你的意思是相同数量的lines, split
有一个选项:
split --lines=75
如果你需要知道那是什么75
真的应该是为了N
等份,其:
lines_per_part = int(total_lines + N - 1) / N
总行数可以通过以下方式获得wc -l
.
请参阅以下脚本的示例:
#!/usr/bin/bash
# Configuration stuff
fspec=qq.c
num_files=6
# Work out lines per file.
total_lines=$(wc -l <${fspec})
((lines_per_file = (total_lines + num_files - 1) / num_files))
# Split the actual file, maintaining lines.
split --lines=${lines_per_file} ${fspec} xyzzy.
# Debug information
echo "Total lines = ${total_lines}"
echo "Lines per file = ${lines_per_file}"
wc -l xyzzy.*
这输出:
Total lines = 70
Lines per file = 12
12 xyzzy.aa
12 xyzzy.ab
12 xyzzy.ac
12 xyzzy.ad
12 xyzzy.ae
10 xyzzy.af
70 total
更新的版本split
允许您指定多个CHUNKS
与-n/--number
选项。因此你可以使用类似的东西:
split --number=l/6 ${fspec} xyzzy.
(that's ell-slash-six
, 意义lines
, not one-slash-six
).
这将为您提供大小大致相等的文件,并且没有中线分割。
我提到最后一点是因为它并没有给你大致相同的数量lines在每个文件中,更多相同数量的人物。
因此,如果您有 1 个 20 字符行和 19 个 1 字符行(总共 20 行)并分成 5 个文件,您很可能won't每个文件中有四行。