I move (mv) files to an outside directory (SAFE_DIR_FOR_DEL) -PLEASE CREATE THIS directory BEFORE EXECUTING the loops- in order to check them later for safety, then you can delete the whole directory. Also, this solution can find multiple patterns per file.
str_rp = You put here whatever you would like to find. Note that some characters may need to be escaped eg. !, "", (), etc (see grep/regex help). You may change the files that you like to search the grep string eg. *.html, *.txt or whatever.
Note that if any pattern of 2 are found, the file is moved into the SAFE_DIR_FOR_DEL. If you like to move files in two different directories, you can easily change the name of the folder in 2nd pattern, but first you must have create it.
CAUTION: before executing it, you try it in some files in an temporary folder with temporary files, with temporary safe dir structure.
i=1; for fl in *.html; do
str_rp="1st pattern";
if n=$(grep "$str_rp" "$fl"); then
echo "OK1-" "$fl"
mv -- "$fl" ../SAFE_DIR_FOR_DEL/;
else
echo "NONE 1st"
fi
# if file moved from 1st grep, then 2nd grep may result normally an error "No such file or directory".
str_rp="2nd pattern";
if n=$(grep "$str_rp" "$fl"); then
echo "OK2-" "$fl"
mv -- "$fl" ../SAFE_DIR_FOR_DEL/;
else
echo "NONE 2nd"
fi
echo $i; let "i+=1";
done;
Or, more concisely:
for pattern in "1st pattern" "2nd pattern"; do
for file in *.html; do
if grep -q -e "$pattern" -- "$file"; then
mv -- "$file" ../SAFE_DIR_FOR_DEL/
fi
done
done
or
for file in *.html; do
if grep -q -e "1st pattern" -e "2nd pattern" -- "$file"; then
mv -- "$file" ../SAFE_DIR_FOR_DEL/
fi
done