I have a textfile.txt like this:
First Line Second Line Third Line Fourth Line Fifth Line Sixth Line
How can I remove the first three lines and the last line most comfortable?
Click the line, connector, or shape that you want to delete, and then press Delete. Tip: If you want to delete multiple lines or connectors, select the first line, press and hold Ctrl while you select the other lines, and then press Delete.
To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete. Otherwise, sed will delete all the lines.
with open('textfile.txt') as old, open('newfile.txt', 'w') as new: lines = old.readlines() new.writelines(lines[3:-1])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With