hack out chunk from large text file?

J

Jason Kinkade

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
 
J

Jürgen Exner

Jason said:
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
 
A

Anno Siegel

Jason Kinkade said:
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
 
T

Tad McClellan

Jason Kinkade said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top