csplit : ファイルを指定の区切り文字で分割
[構文] csplit オプション ファイル パターン
パターン
INTEGER 指定された行番号までをコピー (指定された行番号は含まない)
/REGEXP/[OFFSET] パターンにマッチする行までをコピー (一致する行は含まない)
%REGEXP%[OFFSET] パターンにマッチする行までをスキップして その後をコピー (一致する行は含まれない)
{INTEGER} 前のパターンを指定された回数繰り返す
{*} 前のパターンを終わりまで繰り返す
オプション
-b FORMAT %02d の代わりに sprintf FORMAT を使用
-f PREFIX 出力ファイル名に PREFIX を使用する (デフォルトは 'xx')
-k エラーの場合でも出力ファイルを削除しない
-n DIGITS 接尾辞の数字を 2 桁ではなく 指定された桁数にする
-s 出力ファイルサイズのカウントを出力しない
-z 空の出力ファイルは削除する
使用例 :
[root@localhost ~]# cat testfile.txt
testfile1
testfile1 testfile1

testfile2 testfile2
testfile2

testfile3 testfile3 testfile3
testfile3 testfile3

[root@localhost ~]# csplit -s -n 3 -f testfile.txt testfile.txt '/^$/' {*}

[root@localhost ~]# ls -l
total 20
-rw-------. 1 root root 1024 Sep 19  2022 anaconda-ks.cfg
-rw-r--r--. 1 root root  112 Nov 17 15:33 testfile.txt
-rw-r--r--. 1 root root   30 Nov 17 15:47 testfile.txt000
-rw-r--r--. 1 root root   31 Nov 17 15:47 testfile.txt001
-rw-r--r--. 1 root root   51 Nov 17 15:47 testfile.txt002

[root@localhost ~]# cat testfile.txt000
testfile1
testfile1 testfile1

[root@localhost ~]# cat testfile.txt001

testfile2 testfile2
testfile2

[root@localhost ~]# cat testfile.txt002

testfile3 testfile3 testfile3
testfile3 testfile3