Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify where to save files that result from running the unix split command?

Tags:

unix

split

Is there a way to tell the split command to save the resultant files in a particular location?

like image 933
Walker Avatar asked Jan 15 '11 17:01

Walker


People also ask

How does Unix split work?

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 .

How do you split two files in UNIX?

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.

How split a directory in Linux?

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.


2 Answers

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.

like image 60
thkala Avatar answered Sep 29 '22 07:09

thkala


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 

POSIX

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].)

like image 35
Jonathan Leffler Avatar answered Sep 29 '22 08:09

Jonathan Leffler