deleting lines in a file that match a pattern without opening it

In Unix, how do I delete lines in a file that match a particular pattern without opening it. File contents are

foo line1
misc
whatever
foo line 2

i want to delete all lines that have the pattern "foo" without opening the file. File should eventually contain

misc
whatever

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.