Skip to main content

linux - Remove all files NOT containing a pattern in the contents

How do I remove all files not containing a specified text.


I understand the solution to remove files with a specified text, but I need to remove files NOT containing a specified pattern.


The following command creates a list of files not containing "successful run":


grep -c "successful run" *.out | grep -v ":1" > err.txt

I wish to directly delete these files.

Comments