1. read from the input file, and 2. write only lines that you want to write to a temporary output file, and 3. close the input file 4. rename the temporary output file to the input file's name.