Answers for "remove particular line from files"

1

how to delete a specific line in a file

searched = "snow" # every line containing the variable "searched" will be deleted

with open("file.txt","r+") as f: # open your file
    new_f = f.readlines()
    f.seek(0)
    for line in new_f:
        if searched not in line:
            f.write(line)
    f.truncate() # close your file
Posted by: Guest on February-08-2021
0

delete lines text file linux

sed -i '' '/pattern to match/d' ./infile
Posted by: Guest on October-20-2020

Code answers related to "remove particular line from files"

Python Answers by Framework

Browse Popular Code Answers by Language