PDA

View Full Version : [all variants] command to split text file into small files?



sheshbesh
April 20th, 2009, 08:09 PM
Hi, I have one text file of about 1MB, say big.txt
I want to break it into many small text files of 4KB, say small0 01.txt to small250.txt
I am looking for a command line solution (probably involving a simple loop in a bash script).
In particular, can I use "cut" somehow but instead of a delimeter, use byte-size?

steve101101
April 20th, 2009, 08:12 PM
http://ubuntuforums.org/showthread.php?t=652132

unutbu
April 20th, 2009, 08:13 PM
split --bytes=4K --numeric-suffixes big.txt
Will create 4 KiB files called x00, x01, etc.

steve101101
April 20th, 2009, 08:13 PM
lxsplit makes this very easy.

sheshbesh
April 21st, 2009, 10:35 PM
thanks guys- split worked great
(where do i find lxsplit? what is the difference?)

hyperyoda
April 22nd, 2009, 06:37 AM
Hi, I have one text file of about 1MB, say big.txt
I want to break it into many small text files of 4KB, say small0 01.txt to small250.txt
I am looking for a command line solution (probably involving a simple loop in a bash script).
In particular, can I use "cut" somehow but instead of a delimeter, use byte-size?

$ split –bytes=1{b,k,m} <src-file> <dest-prefix>

src-file = your big file
dest-prefix = the prefix each smaller file will have

b = bytes
k = kilobytes
m = megabytes

so for 1MB chunks you would do:

$ split –bytes=1m big-file.txt small


to restore the original file do:

$ cat small* > big-file-restored.txt

Enjoy!