Reputation: 49
I want to exclude "cgs" and "CGS" but select all other data.
Testdata:
exclude this-->
C
SP999_20151204080019_0054236_000_CGS.csv
CSP999_20151204080019_0054236_000_cgs.csv
accept all other.
I tried something like this .*([Cc][Gg][Ss]).*
to select the cgs, but I don't understand the exclude thing =) It must be a filename_pattern without grep.
Kind Regards,
Bobby
Upvotes: 3
Views: 4798
Reputation: 22428
Using invert match of grep:
grep -v 'cgs\|CGS' <filelist
Or,
ls | grep -v 'cgs\|CGS'
Upvotes: 0
Reputation: 70822
extglob
bash optionTry this:
ls -ld $path/!(*[cC][gG][sS].csv)
And have a look at
man -Pless\ +/extglob bash
If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated by a |. Composite patterns may be formed using one or more of the fol‐ lowing sub-patterns: ?(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: 1
Reputation: 22237
Does it have to be a regexp? You can easily do it with a glob pattern, if you set in your script
shopt -o extglob
to enable extended globbing. You would then use the pattern
!(*[Cc][Gg][Ss]*)
to generate all entries which do NOT have CGS in their name.
Upvotes: 1