Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Jun 2019 01:40:26 +0200
From:      Polytropon <freebsd@edvax.de>
To:        Paul Schmehl <pschmehl_lists@tx.rr.com>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: How to un-select files in shell wildcard patterns
Message-ID:  <20190622014026.88ddb051.freebsd@edvax.de>
In-Reply-To: <94FB6F4A679CD506CC02DCF2@Pauls-MacBook-Pro.local>
References:  <20190621054909.c6ba47ab.freebsd@edvax.de> <94FB6F4A679CD506CC02DCF2@Pauls-MacBook-Pro.local>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 21 Jun 2019 10:44:56 -0500, Paul Schmehl wrote:
> --On June 21, 2019 at 5:49:09 AM +0200 Polytropon <freebsd@edvax.de> wrote:
> 
> > I'm interested in a convenient method to "un-select" files
> > when using regular (sh) shell wildcards. It's quite easy to
> > describe things like
> >
> > 	*.tex
> >
> > to perform an operation on all LaTeX source files, or
> >
> > 	*a*
> >
> > on all files whose name contains (at least) one "a". Patterns
> > that are based on the inclusion of certain attributes are not
> > a problem to deal with using the builtin pattern matching of
> > the shell.
> >
> > But what about the opposite? Let's say, perform an operation
> > on all files _except_ the LaTeX source files, or all files
> > whose name does _not_ contain an "a"?
> >
> > Is there a good method to do this, except creating a kind
> > of "custom regex wrapper script" that does the selection part,
> > for further use with `subshell` or | xargs?
> 
> I feel almost silly trying to suggest anything to *you*, but egrep 
> '(foo|bar|zed|fam). does the trick. So, for example, if you want to do 
> something in the shell to act on all files except ones that end in .tex or 
> have an a in their name:
> ls -al| egrep '(a|\.tex)' * | awk (whatever), etc.

This is exactly what I an trying to avoid, i. e., not depend on
external programs, but instead use what the shell offers interally.

Of course, even regular grep can be used:

	ls | grep -v "a" | xargs ... foo ...

or

	foo `ls | grep -v "a"` ...

could implement the "_not_ this pattern" mechanism (just as the
use of "awk '!/a/" with the ls output, to generate a list of the
matching files (here: those that do _not_ match a certain pattern).

So, is it correct that there is no shell builtin mechanism for
this kind of "negative selection"?




-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20190622014026.88ddb051.freebsd>