Is there a way to tell the split command to save the resultant files in a particular location?
The split command will give each output file it creates the name prefix with an extension tacked to the end that indicates its order. By default, the split command adds aa to the first output file, proceeding through the alphabet to zz for subsequent files. If you do not specify a prefix, most systems use x .
To split a file equally into two files, we use the '-n' option. By specifying '-n 2' the file is split equally into two files.
For each file, we run mkdir -p command that creates a folder dir_001, dir_002, etc. for every hundred files and moves each file into its directory. Each folder is created only if it doesn't exist. In this case, files 1-100 will to into dir_001, files 101-200 will go to dir_002, etc.
How about:
$ split -b 10 input.txt xxx/split-file
or
$ split -b 10 input.txt /tmp/split-file
Just include the output directory in the prefix specification. Keep in mind that the directory must be created beforehand.
This is the MacOS X (BSD) version of split, and includes some features of csplit
:
split [-a suffix_length] [-b byte_count[k|m]] [-l line_count] [-p pattern] [file [name]]
The name
specifies the prefix to the file name - the default is x
, effectively ./x
.
So, you do:
split bigfile /lots/of/little/files/here
The POSIX definition of split
gives the synopses:
split [-l line_count] [-a suffix_length] [file [name]] split -b n[k|m] [-a suffix_length] [file [name]]
(The web site has a repeated typo - no space between file
and [name]
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With