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

后端 未结 18 2416
生来不讨喜
生来不讨喜 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:50

    perl -i    -nle'/regexp/||print' file1 file2 file3
    perl -i.bk -nle'/regexp/||print' file1 file2 file3
    

    The first command edits the file(s) inplace (-i).

    The second command does the same thing but keeps a copy or backup of the original file(s) by adding .bk to the file names (.bk can be changed to anything).

提交回复
热议问题