3

I'm checking the output from a script. In some cases the script has failed, and a certain file hasn't been produced. I want to check whether this file is present in a directory and if not, print the directory name. The directories look like:

6680_4#22_SMALT

All the numbers before _SMALT are variable (they are a unique identifier), and the file within the directory will look something like:

6680_4#22.bam 

in this case, again, the numbers before .bam are variable (they will match the prefix of the directory, i.e. the i.d. before _SMALT). There are similar questions posted, but I'm not that familiar with bash script. Some explanations would be useful, and also, my problem seems complicated by the fact that the file names change in their prefix. Any help would be greatly appreciated.

1 Answer 1

2

Something like this would work:

for dir in `find ./serverfault -maxdepth 1 -type d`
do
  find_output=$( find ${dir} -type f -name "*#*_SMALT" )
  test -z "${find_output}" && echo $dir
done

This for loop does the following:

  1. Get a list of directories in the specified location.
  2. For each directory run a find command to look for the desired file name.
  3. Check if the output of the find command is empty. If it is print the directory name.

To get the inverse results use test -n to check if the output of that find command has found something.

Edit: I completely misunderstood the question so I rewrote my answer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .