# Splitting up a file

**URL:** <https://www.ruby-forum.com/t/splitting-up-a-file/184552>\
**Category:** Ruby\
**Created:** [March 4, 2010, 11:21am UTC](https://www.ruby-forum.com/t/splitting-up-a-file/184552 "2010-03-04T11:21:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [March 4, 2010, 11:21am UTC](https://www.ruby-forum.com/t/splitting-up-a-file/184552/1 "2010-03-04T11:21:01Z")

</div>

Hey,

I have a quick question about breaking up a file into smaller files.

I have a large file, quite like an mbox file in how it stores its data  
for example

DATA  
stuff  
stuff

DATA  
stuff

DATA  
stuff  
stuff

I don’t want this information in one file, I want to break it up into  
single files, so the example above would give me three files. How would  
you suggest I go about this?

Any help is greatly appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [March 4, 2010, 11:39am UTC](https://www.ruby-forum.com/t/splitting-up-a-file/184552/2 "2010-03-04T11:39:18Z")

</div>

On Thu, Mar 4, 2010 at 11:21 AM, Stuart C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> stuff
> 
> DATA  
> stuff  
> stuff
> 
> I don’t want this information in one file, I want to break it up into  
> single files, so the example above would give me three files. How would  
> you suggest I go about this?

If you are on linux, you can use csplit:

csplit testsplit.txt /DATA/ “{\*}”

(this will generate files named xx00, xx01, etc).

Jesus.
