Dear Josep,
Here is the script:
Code:
#!/bin/bash
# include directories
include='include.txt'
# exclude directories
exclude='exclude.txt'
# results
result='result.txt'
[ ! -f $include ] && { echo "Invalid include file"; exit; }
[ ! -f $exclude ] && { echo "Invalid exclude file"; exit; }
# build search path string
for dir in $(cat $include)
do
[ -d $dir ] && searchpath=$searchpath$dir" "
done
[ -z "$searchpath" ] && { echo "No valid search path found in include file"; exit; }
# build exclude path string
for dir in $(cat $exclude)
do
[ -d $dir ] && excludepath=$excludepath" -path $dir -prune"
done
excludepath=${excludepath//-prune -path/-prune -o -path}
[ -n "$excludepath" ] && excludepath=$(echo \( $excludepath \) -o | tr -s " ")
# build find argument string
arg=$(echo "$searchpath $excludepath -type f -print" | tr -s " ")
# run find
find $arg > $result
This script will examine the include and exclude files and then create strings of valid include directories and valid exclude directories. These strings will be used to create the final argument string to find command. The search result will be saved in the file specified by result variable.
I have tested the script for a few test cases and it worked well. Please test the script and let me know if this helps.
Thanks,
Lijeesh