Step 1.) Create a list of all applicable directories, sort it in alphanumeric order and make sure there are no duplicates. Save the list in a temporary file:
find /work/user/folder1/ [...] -type d | sort | uniq > all_directories.txt
Step 2.) Create a list of all *.grid
files.
find /work/user/folder1/ [...] -name *.grid > grid_files.txt
Step 3.) Work through the list of *.grid
files, take the directory name of each file, and again make sure there are no duplicates:
while read FILENAME
do
echo $(dirname "$FILENAME")
done < grid_files.txt | sort | uniq > dirs_with_gridfiles.txt
Step 4.) Run those two lists together and sort the result again. Now, directories with *.grid
files should be listed exactly twice each, and directories with no *.grid
files exactly once each. So you can tell uniq
to report only the non-repeated lines:
cat all_directories.txt dirs_with_gridfiles.txt | sort | uniq -u > dirs_with_no_gridfile.txt
And there you'll have it.