views:

55

answers:

2

Dear all,

I'm a newbie in bash and I would like to pass as parameter to a python function all files in a directory that don't match a given pattern. sth. like:

$myscripts/myprog.py $myfiles/!(bonjovi)

The above example should retrieve all files that don't match to "bonjovi".

Best wishes

+1  A: 

It's probably easiest to use grep, xargs and a regular expression. grep -v excludes lines (in this case filenames) matching a given pattern.

ls | grep -v 'bonjovi' | xargs myscripts/myprog.py
Charles Bailey
Great, thanks Charles! How could I also use regular expression for the grep parameter? let's say:ls | grep -v '*bonjovi_album1*' | xargs myscripts/myprog.pyI made a small test, but "bonjovi_album1" is also retrieved in the output.
Javier
`*bonjovi_album1*` isn't a valid regular expression because there's nothing before the first `*`. `echo bonjovi_album1 | grep -v 'bonjovi_album1*'` works for me but it might not be doing what you expect. It removes anything containing `bonjovi_album` followed by 0 or more `1` s. In this case it's equivalent to the pattern `bonjovi_album`.
Charles Bailey
+1  A: 

You have the syntax exactly right. You just need to enable it.

shopt -s extglob
Dennis Williamson