How would I use sed to delete all lines in a text file that contain a specific string?
There are many other ways to delete lines with specific string besides sed
:
awk '!/pattern/' file > temp && mv temp file
ruby -i.bak -ne 'print if not /test/' file
perl -ni.bak -e "print unless /pattern/" file
while read -r line
do
[[ ! $line =~ pattern ]] && echo "$line"
done o
mv o file
grep -v "pattern" file > temp && mv temp file
And of course sed
(printing the inverse is faster than actual deletion):
sed -n '/pattern/!p' file