Aaron Yodaiken
Aaron Yodaiken

Reputation: 19551

* but excluding certain files

I'd like to do something like

cat *

but which would ignore files that match the pattern __*__.

What's the best way to do this?

Upvotes: 0

Views: 169

Answers (4)

From my today's answer for similar question

ls --ignore="__*__" --quoting-style=shell | xargs cat

Upvotes: 2

Kevin
Kevin

Reputation: 56059

If you enable extglob in bash (shopt -s extglob), you can use

cat !(excluded_file|excluded_*_pattern)

extglob patterns:

| 
    or/alternatives
?(pattern-list)
    Matches zero or one occurrence of the given patterns
*(pattern-list)
    Matches zero or more occurrences of the given patterns
+(pattern-list)
    Matches one or more occurrences of the given patterns
@(pattern-list)
    Matches one of the given patterns
!(pattern-list)
    Matches anything except one of the given patterns

Upvotes: 3

Fredrik Pihl
Fredrik Pihl

Reputation: 45662

$ ls
__a__  __b__  c

$ cat *
aaaaaaaaaaaaa
bbbbbbbbbbbbbb
ccccccccccccccc

$ cat [!_]
ccccccccccccccc

Upvotes: 1

Keith Thompson
Keith Thompson

Reputation: 263257

Perhaps not the best way, but:

tcsh -c 'echo ^__*__'

Upvotes: 1

Related Questions