I have a variable called
$dirs
root/animals/rats/mice
root/animals/cats
$remove
rats
crabs
for d in $remove; do
dirs=$(echo "$dirs" | sed "/\b$d\b/d")
done
root/animals/cats
You are looking for something like
echo "${dirs}" | grep -Ev "rats|crabs"
When you can't store the exclusion list in the format with |, try to change it on the fly:"
echo "${dirs}" | grep -Ev $(echo "${remove}" | tr -s "\n" "|" | sed 's/|$//')
You can use the excludeFile technique without a temp file with
echo "${dirs}" | grep -vf <(echo "${remove}")
I am not sure which of there solutions will be best supported.