# Shell(bash3.2+) while read -r line do [[ ! $s =~ pattern ]] && echo "$line" done <file > o mv o file # GNU grep grep -v "pattern" file > temp && mv temp file # sed (printing the inverse is faster than actual deletion). Need -n. sed -n '/pattern/!p' file