[SD] Editing and removing specific lines from text file

Hello everyone, I'm kind of lost how to do the following. In my program the Arduino is programmed to register data from specific sensors at specific moments. On some occasions, the program will have to edit a value in a line, or dlete a line alltogether. Does anyone know how to do this?

As long as you know where the data in the file is that you're going to edit, you can use fseek to move there and overwrite. This will be considerably easier if you use fixed size records. Deleting is harder. It would be easier to include some marker on the record that indicates whether it is to be considered for use by whatever process consumes the file - a soft delete if you will. If you really want the record gone, you'll need to copy the file record by record to a new file, omitting to copy the one(s) you're dropping. This may be fairly slow if your file is large.

(delete …)
but if you have fixed size records and the order is no issue you can copy the last record over the to be deleted one. That would be very fast.

Better follow wildbills advice and add a marker indicating the validness of every line. Big databases work this way for ages. You could add a line number of 3 digits in every line and set this number to -1 to indicate

wildbill: As long as you know where the data in the file is that you're going to edit, you can use fseek to move there and overwrite. This will be considerably easier if you use fixed size records. Deleting is harder. It would be easier to include some marker on the record that indicates whether it is to be considered for use by whatever process consumes the file - a soft delete if you will. If you really want the record gone, you'll need to copy the file record by record to a new file, omitting to copy the one(s) you're dropping. This may be fairly slow if your file is large.

Thanks for the reply. I still have a few questions left. As the file won't be very big, I've just decided to, indeed, copy it record for record. About the overwriting, if the fseek function the same as file.sek int he SD library for arduino? Also, would file.print/file.write overwrite any data on that position?

Haven't tried it, but yes, I believe so.

Also, would you maybe have an example of how to copy everything to a new file (and back) using the standard SD library? I thought I had it, but it failed a bit.

Post what you have - someone will have advice for you I'm sure