When you want execute an action on a set of files (all, which contain testfile), this technique is pretty straight forward:

1
2
3
4
for line in `find . | grep "testfile"`
do
rm "$line"
done

But this actually does not work, if the file name contains spaces!

In this cases the "while read"-construct is failsafe:

1
2
3
4
find . | grep "testfile" | while read line
do
rm "$line"
done