如何用循环法分割文件

如何用循环法分割文件

我正在阅读 split --help,但我不确定如何使用循环功能执行此命令,有人可以给我举个例子吗

Usage: split [OPTION]... [FILE [PREFIX]]

-n, --number=CHUNKS     generate CHUNKS output files; see explanation below

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

CHUNKS may be:
    N       split into N files based on size of input
    K/N     output Kth of N to stdout
    l/N     split into N files without splitting lines/records
    l/K/N   output Kth of N to stdout without splitting lines/records          
--> r/N     like 'l' but use round robin distribution
    r/K/N   likewise but only output Kth of N to stdout

答案1

在 Bash 中执行的示例:

# create a testfile with 10 lines
$ printf 'line %s\n' {1..10} > testin

# split into 3 files with round robin distribution and numeric suffix (`-d`)
$ split -d -nr/3 testin testout

# show line count
$ wc -l testout*
 4 testout00
 3 testout01
 3 testout02
10 total

# show content
$ head testout*
==> testout00 <==
line 1
line 4
line 7
line 10

==> testout01 <==
line 2
line 5
line 8

==> testout02 <==
line 3
line 6
line 9

相关内容