Reputation: 33
I have multilevel directory structure and I want to list all (png,jpeg files), except files, say, sam.png, pam.jpeg etc from any directory
Ultimately, I want to list all files as
a/b/c/d*.jpg (inlude all jpg, but I want to exclude sam.png from a/b/c/d directory)
a/b/c/d*.jpeg
a/b/c/d*.png
a/e/f/k/h/*.png
...and so on
How do I do that?
Upvotes: 0
Views: 887
Reputation: 48
Use following regex
-
.(jpg|jpeg|gif|png)$(?<!sam.png|pam.jpeg)
This uses negative look behind.
Upvotes: 3
Reputation: 144
I'm not completly sure of the context of you problem.
However you can use find .
to list and files under a directory (recursive).
Use egrep
to filter the result with a regexp.
And then use egrep -v
to filter in a negative way (if it doesn't match stays).
So I guess something like this might do the job:
find . | egrep "*.(jpg|png)$" | egrep -v "*.(sam.png)"
Upvotes: 0