Delete multiple lines of text from text file - Forum

Forum Navigation
You need to log in to create posts and topics.

Delete multiple lines of text from text file

Anyone have a good routine for deleting a block of text from a text file? Like delete lines 14 thru 156?

Hello,

Would FileDelLine not do the job?

With a loop from 1 to 142 and a FileDelLine 14 it should do it.

Not tested! ;-)

Regards

Hans-Peter

 

@wrangler
@hpw

With a loop from 1 to 142 and a FileDelLine 14 it should do it.

Yes, but note that when you delete a line at number x, all lines previously at 'x+1' to 'end of file' will now be 'one less than before the delete' so you have to run the loop backwards (line 142 to 1).

Thanks guys. I tried the loop trick early on but ran into the "less lines than before" dilemna. Never thought of or even knew you could run a loop backwards. :lol

Gaev,

When I delete 142 x line 14 then I delete line 14-156.

Regards

Hans-Peter

 

 

 

@hpw

When I delete 142 x line 14 then I delete line 14-156.

OK, now I understand what you meant ... I missed the reference to Line 14 in Wrangler's first post and so I thought there was a typo in your response.

Yes, that would be another way to use the Loop/EndLoop ... delete the same line number in each iteration of the Loop.

Quote from HPW on November 7, 2020, 8:43 pm

Gaev,

When I delete 142 x line 14 then I delete line 14-156.

Regards

Hans-Peter

 

 

 

Yes, this is the way I usually use.

There is another way too, but it is slower.
Copy the lines that you do not want to delete in another file, delete the original file and rename the new file.

Greetings.