Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > hack out chunk from large text file?

Reply
Thread Tools

hack out chunk from large text file?

 
 
Jason Kinkade
Guest
Posts: n/a
 
      10-04-2004
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
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      10-04-2004
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


 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      10-04-2004
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
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      10-04-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sending a file chunk by chunk instead as a whole to a web server Sanjeeb Python 3 08-03-2010 05:52 AM
reading large file in chunks: optimal chunk size? bwv549 Ruby 3 06-17-2009 07:29 PM
Efficient large chunk of memory copy? -- copy diffs? Developer C++ 4 02-25-2009 06:06 PM
What is an AVI Chunk Viewer? - AVI Chunk Viewer.jpg (0/1) mazdra76@yahooo.com Computer Support 1 03-17-2006 02:52 AM
Need speed increase while reading large chunk of data. Darsant C++ 8 06-11-2005 03:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57