Split (Unix)

Revision as of 05:53, 23 January 2025 by imported>RJFJR (remove {{how-to|date=June 2013}})
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Template:Lowercase title {{#invoke:Infobox|infobox}}Template:Template other{{#invoke:Check for unknown parameters | check | showblankpositional=1 | unknown = Template:Main other | preview = Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y | AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo upright | logo size | logo title | logo_alt | logo_caption | logo_upright | logo_size | logo_title | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot upright | screenshot size | screenshot title | screenshot_alt | screenshot_upright | screenshot_size | screenshot_title | service_name | size | standard | title | ver layout | website | qid }}Template:Main other split is a utility on Unix, Plan 9, and Unix-like operating systems most commonly used to split a computer file into two or more smaller files.

HistoryEdit

The <syntaxhighlight lang="text" class="" style="" inline="1">split</syntaxhighlight> command first appeared in Version 3 Unix<ref>Template:Man</ref> and 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.<ref>Template:Man</ref> The version of split bundled in GNU coreutils was written by Torbjorn Granlund and Richard Stallman.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> The Template:Mono command has also been ported to the IBM i operating system.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>

UsageEdit

The command-syntax is: <syntaxhighlight lang="bash">

split [OPTION] [INPUT [PREFIX]]

</syntaxhighlight>

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 utility 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 piecesEdit

Create a file named "myfile.txt" with exactly 3,000 lines of data: <syntaxhighlight lang="console"> $ head -3000 < /dev/urandom > myfile.txt </syntaxhighlight>

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): <syntaxhighlight lang="console"> $ 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

</syntaxhighlight> 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.

See alsoEdit

ReferencesEdit

Template:Reflist

External linksEdit

Template:Sister project

Template:Unix commands Template:Plan 9 commands Template:Core Utilities commands


Template:Unix-stub