Назад | Перейти на главную страницу

Как разделить файл с помощью кругового алгоритма

Я читаю 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

Пример, выполненный в 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