Friday, August 24, 2001

Split files

Some times you need to split a big file into a set of smaller ones, for example to send them by email. If the file is a "text" one and not too huge you can always try with an editor. But if the file contains non-standard characters (I mean, the one used in daily life) or it is too big, an editor is not a good way of dividing the file. There is a UNIX command that does this job: split. Used simply as in the example below will divide the file into smaller ones, named in a pattern like xaa, xab, etc. Here is the example:

split file-name

There are options to split to control the way the file is divided:

  1. -b number-of-bytes will put at most that number of bytes on each of the smaller output files;
  2. -l number-of-lines is similar to the previous option, but with lines;
  3. -a number will use number of characters for the names of the output files, for example, if you do -a 3 your files will be called xaaa, xaab, etc;
  4. -d will use numbers for the names of the output files, like x00, x01, etc;
  5. –verbose will show you what output files are being written.

In some sense split is the opposite of cat