Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use wildcard with exception in bash? [duplicate]

I want to grep multiple files in a folder. I want to grep everyone of them except big files like pcap file and gziped files. So I am trying :

$ grep foo !({*pcap*,*gz*})

But that does not work. Because while it avoid gziped files, the shell expansion of !({*pcap*,*gz*}) returns pcap files actually. Any idea how to include every files except pcap and gziped files please?

like image 787
yves Baumes Avatar asked Dec 28 '25 17:12

yves Baumes


2 Answers

The GLOBIGNORE parameter lists files to exclude from the results of a glob expansion:

Assuming the current directory is empty:

$ touch foo1 foo2 foo3 foo10 foo11 foo12
$ GLOBIGNORE="foo1*:foo3"
$ ls *
foo2
like image 178
chepner Avatar answered Dec 31 '25 11:12

chepner


you need to change that to

grep foo  !(*pcap*|*gz*)

to exclude pcap and gz files

like image 41
iruvar Avatar answered Dec 31 '25 12:12

iruvar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!