Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux csplit Command

Linux csplit Command

Linux Command Reference Linux Command Reference

The Linux csplit command is used to split files.

Split the file according to the specified pattern and save the pieces as files named xx00, xx01, xx02... If the given file name is "-", the csplit command reads data from standard input.

Syntax



csplit [-kqsz][-b<输出格式>][-f<输出字首字符串>]

[-n<输出文件名位数>][--help][--version][文件][范本样式...] 

Parameters:

Example

Split the text file testfile into two parts at line 2, using the following command:



csplit testfile 2

The contents of the file testfile are as follows:



$ cat testfile #查看testfile 文件内容  

hello Linux!  

Linux is a free Unix-type operating system.  

This is a Linux testfile!  

Linux 

Using the csplit command, the output is as follows:



$ csplit testfile 2  

13 #xx00文件字符个数  

76 #xx01文件字符个数  

The first line is the character count of the first file xx00; likewise, the second line is the character count of the second file xx01. At the same time, two files will be generated in the same directory as testfile, named xx00 and xx01. The contents of xx00 are:



$ cat xx00 #查看分割后的xx00文件内容  

hello Linux! #testfile文件第1行的内容 

The contents of xx01 are:



$ cat xx01 #查看分割后的xx01文件内容  

Linux is a free Unix-type operating system. #testfile文件第2行以后的内容  

This is a Linux testfile!  

Linux 

Linux Command Reference Linux Command Reference