split (Unix)

split is a utility on Unix and Unix-like operating systems most commonly used to split a computer file into two or more smaller files.

split
Developer(s)Various open-source and commercial developers
Initial releaseFebruary 1973 (1973-02)
Operating systemUnix and Unix-like
TypeCommand

History

split is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification.[1] It first appeared in Version 3 Unix.[2]

The version of split bundled in GNU coreutils was written by Torbjorn Granlund and Richard Stallman.[3]

Usage

The command-syntax is:

 split [OPTION] [INPUT [PREFIX]]

The default behavior of split is to generate output files of a fixed size, default 1000 lines. The files are named by appending aa, ab, ac, etc. to output filename. If output filename is not given, the default filename of x is used, for example, xaa, xab, etc. When a hyphen (-) is used instead of input filename, data is derived from standard input. The files are typically rejoined using a utilitity such as cat.

Additional program options permit a maximum character count (instead of a line count), a maximum line length, how many incrementing characters in generated filenames, and whether to use letters or digits.

Split file into pieces

Create a file named "myfile.txt" with exactly 3,000 lines of data:

$ head -3000 < /dev/urandom > myfile.txt

Now, use the split command to break this file into pieces (note: unless otherwise specified, split will break the file into 1,000-line files):

$ split myfile.txt
$ ls -l
-rw-r--r--  1 root root 761K Jun 16 18:17 myfile.txt
-rw-r--r--  1 root root 242K Jun 16 18:17 xaa
-rw-r--r--  1 root root 263K Jun 16 18:17 xab
-rw-r--r--  1 root root 256K Jun 16 18:17 xac
$ wc --lines xa*
  1000 xaa
  1000 xab
  1000 xac
  3000 total

As seen above, the split command has broken the original file (keeping the original intact) into three, equal in number of lines (i.e., 1,000), files: xaa, xab, and xac.

Manual

  • split  Commands & Utilities Reference, The Single UNIX Specification, Issue 7 from The Open Group
gollark: I mean, possibly good if you want to run computer vision fast, but otherwise bad.
gollark: No, they're just bad.
gollark: That's not really very acronym-y. They generally just remove boring words like "he" or "or".
gollark: Could you use this for pangram generation? That might be cool.
gollark: I see.

See also

References

  1. split  Commands & Utilities Reference, The Single UNIX Specification, Issue 7 from The Open Group
  2. split(1)  FreeBSD General Commands Manual
  3. https://linux.die.net/man/1/split
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.