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.
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.
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.
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.
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.
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.
Issue the following faulty command:
3.
It is also called the digits flag.
The fifth line in the original file has the word “Berlin.”
In the output file, “Berlin” was omitted.
One of them is csplit.
By default, it is available on all Linux systems.
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.