csplit: split files from the terminal of your GNU / Linux distro

Divide files scissor logo cutting pdf

There are many ways to divide a large file into several smaller ones, since it is a fairly daily task that many users need sometimes to, for example, be able to send files by email that do not accept to exceed a specific amount in the attachments, etc. In Windows, many know the Hacha program, which is used for this, and in GNU / Linux we can install other similar alternatives such as Hoz.

I have been using Sickle for some time, but I have not used it again for a long time and I do not know the status of the project at present. Also exist other alternatives like Dalle, with a simple graphical interface that will help us divide the files we want into as many parts as we want or choose the size of the parts in which it will be fragmented. In addition, Dalle also allows you to select the type of output format for the parts (Ax, SplitFile, ZIP, Generic, Astrotite, etc.).

Surely you will also know other alternatives, but today I am going to talk about a command concrete that you can use from the console of your distro to divide files into parts. That command I'm talking about is called csplit, and surely you have already heard something about it or have used it. But for those who still don't know it, saying that it is a program that allows you to divide files based on their content, instead of on the basis of size like the rest, and that can have advantages.

As you know, split can split files into fixed-size chunks, but csplit It is a variant that will identify the limits of the gram based on the content. For example, imagine that you have a text file called test that you intend to divide into text fragments according to a certain separator that is included in said text. For example, imagine that the test file contains this:

1 -Hola

2 -Esto

3 -Es

4 -Una

5 -Prueba

With the following command, when the line that begins with the number 3 is located, another fragment will be generated and each part will be called hello1 (with lines 1 and 2) and hello2 (with lines 3 to 5):

csplit prueba 3 -f hola

We could also include the number of lines we want. For example, imagine that we want to generate a file that contains up to line 3, the next 3-4 and another with 2 more lines:

csplit prueba 3 {2} -f hola

And of course you can use man csplit to see many more options for this command ...


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.