1searched = "snow" # every line containing the variable "searched" will be deleted
2
3with open("file.txt","r+") as f: # open your file
4 new_f = f.readlines()
5 f.seek(0)
6 for line in new_f:
7 if searched not in line:
8 f.write(line)
9 f.truncate() # close your file
1# Basic syntax:
2sed 'line#d' input_file
3# Where line# is the line you want to delete from the input_file
4
5# Example usage:
6input_file contains:
7this is
8my favorite
9line
10
11sed '2d' input_file
12--> this is
13--> line