#!/usr/bin/python3 # list to store file lines lines = [] # read file with open(r"/home/ronalds/Desktop/SS.txt", 'r') as fp: # read an store all lines into list lines = fp.readlines() # Write file with open(r"/home/ronalds/Desktop/SS.txt", 'w') as fp: # iterate each line for line, words in enumerate(lines): # delete line 5 and 8. or pass any Nth line you want to remove # note list index starts from 0 if all(c not in words for c in ['$', '€']): fp.write(line)