I assume by 'not opening it' you mean without having to edit it. These commands will delete the lines with the indicated patterns, and then replace the file:
sed '/foo/d;' <original-file-name >new-file-name
mv new-file-name original-file-name
You need to execute the move command only if you want to replace the original file, and I suggest running the command and looking at the results to ensure you got the sed command right before replacing the file.