Need a shell script to filter out directories
August 10, 2011 7:52 AM Subscribe
Shell gurus needed! I need a line/script that will create a list of all sub-folders within a folder that do not contain files with a certain filename pattern. There is an additional requirement...(more inside)
Given a folder /somefolder , I need to be able to create a list of all subfolders within /somefolder that:
1) have files of the pattern *.tif
AND
2) do not have files of the pattern *_Aug11.pdf
In other words a folder containing 8107.tif AND 8107_Aug11.pdf would not match the search expression.
However, a folder containing 8107.tif AND 8107.pdf would match, as would a folder containing just 8107.tif alone, or 8107.tif, 8108.tif, etc. provided there are NO associated _Aug11.pdf for each of those.
The script can be a Windows powershell or unix shell script...
posted by dukes909 to computers & internet (12 answers total) 1 user marked this as a favorite
#!/usr/bin/env bash DIR="${1:-.}" (for TIFF in $(find "$DIR" -name '*.tif' -print); do if [ ! -e "${TIFF%.tif}_Aug11.pdf" ]; then echo "$(dirname "$TIFF")" fi done) | uniqYou could make this a one-liner, but ugh. It's also a bit inefficient, because it will keep processing the same directory over and over again even after it finds one example. There are ways to do keep it from doing that but at the expense of making the script a bit more complex.posted by grouse at 8:12 AM on August 10, 2011