Does anyone know of a quick way to delete a line in a file?
Does anyone know of a quick way to delete a line in a file?
Use notepad if you have Microsoft, or else Kate if you have Linux on KDE.
always a comedian.
My understanding is you will have to move everything up. Perhaps load it all into memory, reopen the file truncated, write it back out without the missing line. If it's a big file you could always copy it to a temp file and do it in chunks.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
pseudo-code:
Code:while we aren't at the end of the file { if the line we are reading is the line we want to delete { continue } else { print the line to the new file } } delete the old file
You forgot:
Rename new file to name of old file. I'm assuming that's what he wants.
Try not.
Do or do not.
There is no try.
- Master Yoda
that's what I was getting at. A temp/second file that you will make the altered copy in. There isn't really any way to pull a small piece out of an existing file such that everything collapses together. That's what I think you were looking for.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
I figured I might have to create a new file but I was hoping to get around it.