生成测试文件
[root@server dir]# dd if=/dev/zero bs=100k count=1 of=data.file
按大小切割
[root@server dir]# split -b 10M -d -a4 db-1.log db
$ ls -al
-rw-r--r--. 1 root root 10485760 Feb 13 05:59 db0000
-rw-r--r--. 1 root root 10485760 Feb 13 05:59 db0001
-rw-r--r--. 1 root root 10485760 Feb 13 05:59 db0002
-rw-r--r--. 1 root root 1572864 Feb 13 05:59 db0003
-rw-r--r--. 1 root root 33030144 Feb 13 01:32 db-1.log
按行切割
[root@server dir]# split -l 10000 db-1.log
[root@server dir]# ll
total 38856
-rw-r--r--. 1 root root 33030144 Feb 13 01:32 db-1.log
-rw-r--r--. 1 root root 1195298 Feb 13 06:10 xaa
-rw-r--r--. 1 root root 1260000 Feb 13 06:10 xab
-rw-r--r--. 1 root root 1260000 Feb 13 06:10 xac
-rw-r--r--. 1 root root 1260000 Feb 13 06:10 xad
-rw-r--r--. 1 root root 1260000 Feb 13 06:10 xae
-rw-r--r--. 1 root root 26794846 Feb 13 06:10 xaf
[root@server dir]# vim server.log
SERVER-1
[connection] 192.168.0.1 success
[connection] 192.168.0.2 failed
[disconnect] 192.168.0.3 pending
[connection] 192.168.0.4 success
SERVER-2
[connection] 192.168.0.1 failed
[connection] 192.168.0.2 failed
[disconnect] 192.168.0.3 success
[connection] 192.168.0.4 failed
SERVER-3
[connection] 192.168.0.1 pending
[connection] 192.168.0.2 pending
[disconnect] 192.168.0.3 pending
[connection] 192.168.0.4 failed
[root@server dir]# csplit server.log /SERVER/ -n 2 -s {*} -f server -b "%02d.log" ;
> /SERVER/ is the line used to match a line by which the split is to be carried out.
> /[REGEX]/ is the format. It copies from current line (frst line) upto the matching line
that contains "SERVER" excluding match line.
> {*} is used to specify to repeat splitting based on match upto the end of the fle. By
using {integer}, we can specify no of times it is to be continued.
> -s is the flag to make the command silent rather than printing other messages.
> -n is used to specify the number of digits to be used as suffx. 01, 02, 03, and so on.Have a Good Command
84
> -f is used for specifying the flename prefx for split fles ("server" is the prefx in the
previous example).
> -b is used to specify the suffx format. "%02d.log" is similar to the printf
argument format in C. Here the flename = prefx + suffx = "server" + "%02d.
log".