Linux csplit命令用于分割文件。
將文件依照指定的范本樣式予以切割后,分別保存成名稱為xx00,xx01,xx02...的文件。若給予的文件名稱為"-",則csplit指令會從標準輸入設備讀取數據。
csplit [-kqsz][-b<輸出格式>][-f<輸出字首字符串>] [-n<輸出文件名位數>][--help][--version][文件][范本樣式...]
參數:
將文本文件testfile以第 2 行為分界點切割成兩份,使用如下命令:
csplit testfile 2
testfile文件中的內容如下:
$ cat testfile #查看testfile 文件內容 hello Linux! Linux is a free Unix-type operating system. This is a Linux testfile! Linux
使用csplit命令,輸出結果如下:
$ csplit testfile 2 13 #xx00文件字符個數 76 #xx01文件字符個數
其中第1 行是第一個文件xx00的字符個數,同樣,第2 行為第二個文件xx01的字符個數。同時,在testfile 的同目錄下將生成兩個文件,文件名分別為xx00、xx01,xx00 中的內容為:
$ cat xx00 #查看分割后的xx00文件內容 hello Linux! #testfile文件第1行的內容
xx01 中的內容為:
$ cat xx01 #查看分割后的xx01文件內容 Linux is a free Unix-type operating system. #testfile文件第2行以后的內容 This is a Linux testfile! Linux