Linux csplit Command

Linux 命令大全Linux Command Encyclopedia

The Linux csplit command is used to split files.

After splitting the file according to the specified template pattern, it is saved as files named xx00, xx01, xx02... respectively. If the given file name is "-", the csplit command will read data from the standard input device.

Syntax

csplit [-kqsz][-b<输出格式>][-f<输出字首字符串>]
[-n<输出文件名位数>][--help][--version][文件][范本样式...] 

Parameters:

  • -b<output format> or --suffix-format=<output format> The default output format has file names such as xx00, xx01..., you can change the output file name by modifying <output format>.
  • -f<output prefix string> or --prefix=<output prefix string> The default output prefix string has file names such as xx00, xx01..., if you specify the output prefix string as "hello", the output file names will become hello00, hello01..., etc.
  • -k or --keep-files Keep the files; even if an error occurs or execution is interrupted, the already output and saved files cannot be deleted.
  • -n<output file name digits> or --digits=<output file name digits> The default output file name digit count results in file names such as xx00, xx01..., if you specify the output file name digit count as "3", the output file names will become xx000, xx001..., etc.
  • -q or -s or --quiet or --silent Do not display the command execution process.
  • -z or --elide-empty-files Delete files with a length of 0 bytes.
  • --help Online help.
  • --version Display version information.

Examples

To split the text file testfile into two parts at the boundary of line 2, use the following command:

csplit testfile 2

The content in the testfile file is 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 result is as follows:

$ csplit testfile 2  
13 #xx00文件字符个数  
76 #xx01文件字符个数  

The first line is the number of characters in the first file xx00, and similarly, the second line is the number of characters in the second file xx01. At the same time, two files will be generated in the same directory as testfile, named xx00 and xx01 respectively. The content in xx00 is:

$ cat xx00 #查看分割后的xx00文件内容  
hello Linux! #testfile文件第1行的内容 

The content in xx01 is:

$ cat xx01 #查看分割后的xx01文件内容  
Linux is a free Unix-type operating system. #testfile文件第2行以后的内容  
This is a Linux testfile!  
Linux 

Linux 命令大全Linux Command Encyclopedia

Other Extensions