开发者

List files that don't match a string in bash

开发者 https://www.devze.com 2022-12-28 10:33 出处:网络
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:

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 $myf开发者_Go百科iles/!(bonjovi)

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

Best wishes


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

shopt -s extglob


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
0

精彩评论

暂无评论...
验证码 换一张
取 消