Easy Tutorial
❮ Linux Comm Lsmod Linux System Contents ❯

Linux csplit Command

Linux Command Manual

The Linux csplit command is used to split files.

It splits the file according to specified pattern(s) and saves them as files named xx00, xx01, xx02, and so on. If the given filename is "-", the csplit command reads data from the standard input device.

Syntax

csplit [-kqsz][-b<output format>][-f<output prefix string>]
[-n<output file name digits>][--help][--version][file][pattern...]

Parameters:

Example

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

csplit testfile 2

The content of the testfile is as follows:

$ cat testfile # View the content of 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 # Character count of xx00 file
76 # Character count of xx01 file

The first line is the character count of the first file xx00, and the second line is the character count of the second file xx01. Additionally, two files named xx00 and xx01 will be created in the same directory as testfile. The content of xx00 is:

$ cat xx00 # View the content of the split xx00 file
hello Linux! # Content of the first line of testfile

The content of xx01 is:

$ cat xx01 # View the content of the split xx01 file
Linux is a free Unix-type operating system. # Content from the second line onwards of testfile
This is a Linux testfile!
Linux

Linux Command Manual

❮ Linux Comm Lsmod Linux System Contents ❯