How to un-select files in shell wildcard patterns

Paul Schmehl pschmehl_lists at tx.rr.com
Fri Jun 21 15:45:05 UTC 2019


--On June 21, 2019 at 5:49:09 AM +0200 Polytropon <freebsd at 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.

Paul Schmehl, Retired
My opinions are my own.
*******************************************
"It is as useless to argue with those who have
renounced the use of reason as to administer
medication to the dead." Thomas Jefferson
"There are some ideas so wrong that only a very
intelligent person could believe in them." George Orwell



More information about the freebsd-questions mailing list