Python Forum
Delete multiple lines from txt file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Delete multiple lines from txt file
#2
The best way to do this is:
  1. Copy the lines of the original file to a temporary file, but don't copy the lines you do not want.
  2. If no errors occurred: remove the original file.
  3. Rename the temporary file to the name of the original file.
Reply


Messages In This Thread
Delete multiple lines from txt file - by Lky - Jul-09-2022, 04:43 PM
RE: Delete multiple lines from txt file - by ibreeden - Jul-09-2022, 06:00 PM
RE: Delete multiple lines from txt file - by Lky - Jul-10-2022, 05:32 AM
RE: Delete multiple lines from txt file - by Lky - Jul-10-2022, 05:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write the condition for deleting multiple lines? Lky 3 1,170 Jul-10-2022, 02:28 PM
Last Post: Lky
  failing to print not matched lines from second file tester_V 14 6,168 Apr-05-2022, 11:56 AM
Last Post: codinglearner
  Extracting Specific Lines from text file based on content. jokerfmj 8 3,086 Mar-28-2022, 03:38 PM
Last Post: snippsat
  Find and delete above a certain line in text file cubangt 12 3,535 Mar-18-2022, 07:49 PM
Last Post: snippsat
  How to delete portion of file already processed? Mark17 13 2,787 Jan-22-2022, 09:24 AM
Last Post: Pedroski55
  Delete multiple comments with a single API call (facebook) Ascalon 0 2,334 Dec-04-2021, 08:33 PM
Last Post: Ascalon
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 2,254 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  Display table field on multiple lines, 'wordwrap' 3python 0 1,782 Aug-06-2021, 08:17 PM
Last Post: 3python
  Importing a function from another file runs the old lines also dedesssse 6 2,598 Jul-06-2021, 07:04 PM
Last Post: deanhystad
  [Solved] Trying to read specific lines from a file Laplace12 7 3,576 Jun-21-2021, 11:15 AM
Last Post: Laplace12

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020