csplit is a popular Linux command-line utility used to split the contents of a file into two.

The file you better alter must be a text file with a “.txt” extension.

The command is easy to use and works well on all Linux distributions.

Different Linux files and directories displayed on Terminal

Here’s how to use csplit to split a file on Linux.

What Is csplit?

How to Install csplit on Linux

csplit comes pre-installed on almost all Linux distributions.

a text file is being created on Ubuntu terminal

Usethe touch command to create an empty file.

Once you’ve created the file, open it with the nano editor to modify its content.

once you nail added some content to the file, pressCtrl + Xand thenYto save and close it.

A file and its contents are displayed

The file contains nine lines from numbers 1 to 9.

In the command, you just need to tell csplit from which line to start the split.

This is done by specifying the line number.

On ubuntu terminal, csplit command has been used to split a file

Enter the command like this:

This command will instantly divide the file into two.

Usethe ls commandto list down all the directory contents to see the output files.

You will find the new files with the namesxx00andxx01alongside the original file.

csplit command has been used with -f flag

Use the cat command to verify the contents of both files.

Change the Prefix for Output Files

Also known as the prefix flag,-fmodifies the prefix in the filename.

you might change that by using the-fflag in the command.

csplit command has been used with the k option

Issue the following faulty command:

3.

It is also called the digits flag.

The fifth line in the original file has the word “Berlin.”

csplit command is being used with n flag

In the output file, “Berlin” was omitted.

One of them is csplit.

By default, it is available on all Linux systems.

csplit command is being used with s flag

If not, it’s possible for you to simply install it via the command line.

csplit comes with various command-line options that offer you the flexibility to tailor the output the way you want.

csplit command is being used with h flag

csplit command is being used with v flag

csplit command is being used with suppress matched option