Splitting up a file

Discussion in 'Ruby' started by Stuart Clarke, Mar 4, 2010.

  1. 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
    --
    Posted via http://www.ruby-forum.com/.
     
    Stuart Clarke, Mar 4, 2010
    #1
    1. Advertising

  2. On Thu, Mar 4, 2010 at 11:21 AM, Stuart Clarke
    <> wrote:
    > 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?


    If you are on linux, you can use csplit:

    csplit testsplit.txt /DATA/ "{*}"

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

    Jesus.
     
    Jesús Gabriel y Galán, Mar 4, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page