djpiky
djpiky

Reputation: 45

removing specific row in csv file, python

I woud like to remove (delete) specific rows in csv file. But there are some conditions.

1.) File can't be buffered in memmory, becuse of it's size (1GB+)
2.) File MUST NOT be "touched" (rewriting file) 

My job is just to delete some rows in csv file, without changing any other rows - Very important, becuse of encoding and sending filtered csv file to company which prints that files.

Is there solution?

Thank you!

Upvotes: 0

Views: 265

Answers (3)

philshem
philshem

Reputation: 25371

You can create an old timestamp using 'touch -t'. See the man page of 'touch' for more details.

touch -t 200510071138 old.dat

Just make sure you write down the original timestamp!

In order to remove the rows, you can use 'grep -v', which prints everything except your search terms.

grep -v baddata old.dat > new.dat

To modify with python, we're going to need some specific details of the file.

Upvotes: 0

jorispilot
jorispilot

Reputation: 483

You can try using the mmap interface to replace the row bytes by space characters.

Upvotes: 0

McKay
McKay

Reputation: 12624

It can't be done. You want to delete content from a file, without modifying it. Those are mutually exclusive.

Upvotes: 2

Related Questions