Files

如何使用循環拆分文件

  • April 20, 2019

我正在閱讀 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

引用自:https://serverfault.com/questions/963912