How to delete from a text file, all lines that contain a specific string?

后端 未结 18 2166
生来不讨喜
生来不讨喜 2020-11-22 02:06

How would I use sed to delete all lines in a text file that contain a specific string?

18条回答
  •  难免孤独
    2020-11-22 02:46

    You can use sed to replace lines in place in a file. However, it seems to be much slower than using grep for the inverse into a second file and then moving the second file over the original.

    e.g.

    sed -i '/pattern/d' filename      
    

    or

    grep -v "pattern" filename > filename2; mv filename2 filename
    

    The first command takes 3 times longer on my machine anyway.

提交回复
热议问题