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

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

    to show the treated text in console

    cat filename | sed '/text to remove/d' 
    

    to save treated text into a file

    cat filename | sed '/text to remove/d' > newfile
    

    to append treated text info an existing file

    cat filename | sed '/text to remove/d' >> newfile
    

    to treat already treated text, in this case remove more lines of what has been removed

    cat filename | sed '/text to remove/d' | sed '/remove this too/d' | more
    

    the | more will show text in chunks of one page at a time.

提交回复
热议问题