I have a whole repository of files and I am trying to get a list of files that match a certain criteria.
For example, let us say that I want to take all the files that have the string foo1
and foo2/foo3
in the path and do not have bar1
or bar2/bar3
. Note that it is possible for bar1
or bar2/bar3
to be a sub directory of foo*
and in that case those directories should also be excluded. I tried the following method:
IN_REGEX="$1"
OUT_REGEX="$2"
find . -name '*'.cpp | grep $IN_REGEX | grep -v $OUT_REGEX
I call this script in this way:
./script "/foo1/\|/foo2\/foo3/" "/bar1/\|/bar2\/bar3/"
However, the loop never gets executed. I tried changing the "
in the command line arguments to '
. But that did not help. I tried changing the grep
s to sed
commands like so:
find . -name '*'.cpp | sed "\m%$IN_REGEX%" | sed "\%$OUT_REGEX%d"
Again, no success. However, when I try to execute the grep
on the bash shell directly. It works fine. I have spent the whole day today trying to figure this out.
Can someone please help me out?