hack out chunk from large text file?

Discussion in 'Perl Misc' started by Jason Kinkade, Oct 4, 2004.

  1. I have a text file that looks like.

    ---unique id---
    many lines
    ---------------
    ---unique id---
    many lines
    ---------------
    ---unique id---
    many lines
    ---------------
    ....etc.

    I want to simply remove a section between the ---unique id--- and
    ---------. Now I know I could go through it line by line and output
    the filtered text to a tmp file then copy the tmp file back, but thats
    impracticle with the file is like a gig in size. Does anyone know a
    way I can operate on the text file directly and remove a section
    without copying the whole file to a tmp file or temporatily into
    memory?

    Thanks
    Jason Kinkade, Oct 4, 2004
    #1
    1. Advertising

  2. Jason Kinkade wrote:
    > I have a text file that looks like.

    [...]
    > I want to simply remove a section between the ---unique id--- and


    Did you check "perldoc -q delete":
    How do I change one line in a file/delete a line in a file/insert a
    line in the middle of a file/append to the beginning of a file?

    jue
    Jürgen Exner, Oct 4, 2004
    #2
    1. Advertising

  3. Jason Kinkade

    Anno Siegel Guest

    Jason Kinkade <> wrote in comp.lang.perl.misc:
    > I have a text file that looks like.
    >
    > ---unique id---
    > many lines
    > ---------------
    > ---unique id---
    > many lines
    > ---------------
    > ---unique id---
    > many lines
    > ---------------
    > ...etc.
    >
    > I want to simply remove a section between the ---unique id--- and
    > ---------. Now I know I could go through it line by line and output
    > the filtered text to a tmp file then copy the tmp file back, but thats
    > impracticle with the file is like a gig in size.


    Then you're out of luck. There is n other way.

    > Does anyone know a
    > way I can operate on the text file directly and remove a section
    > without copying the whole file to a tmp file or temporatily into
    > memory?


    Can't be done with today's standard file systems. If you want to
    delete things from the middle of a file, (at least) everything
    following the deletion must be rewritten.

    Anno
    Anno Siegel, Oct 4, 2004
    #3
  4. Jason Kinkade <> wrote:

    > I know I could go through it line by line and output

    ^^^^^^^
    > the filtered text to a tmp file then copy the tmp file back,



    Or you could have Perl do all of that for you by setting $^I
    or using the -i command line switch.


    > Does anyone know a
    > way I can operate on the text file directly and remove a section
    > without copying the whole file to a tmp file or temporatily into
    > memory?



    Nope.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Oct 4, 2004
    #4
    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.
Similar Threads
  1. Darsant
    Replies:
    8
    Views:
    500
  2. Replies:
    6
    Views:
    1,981
  3. Developer
    Replies:
    4
    Views:
    703
    Daniel Pitts
    Feb 25, 2009
  4. Sanjeeb
    Replies:
    3
    Views:
    407
    Ryan Kelly
    Aug 3, 2010
  5. bwv549
    Replies:
    3
    Views:
    409
    Eleanor McHugh
    Jun 17, 2009
Loading...

Share This Page