我想排除" cgs"和" CGS"但是请选择所有其他数据。
TESTDATA:
排除此 - >
C
SP999_20151204080019_0054236_000_CGS.csv
CSP999_20151204080019_0054236_000_cgs.csv
接受所有其他人。
我尝试了类似.*([Cc][Gg][Ss]).*
的内容来选择 cgs ,但我不理解排除的东西=)它必须是没有grep的filename_pattern。
亲切的问候,
巴比
答案 0 :(得分:1)
是否为正则表达式?如果在脚本中设置
,则可以使用glob模式轻松完成shopt -o extglob
启用扩展的globbing。然后,您将使用模式
!(*[Cc][Gg][Ss]*)
生成名称中没有CGS的所有条目。
答案 1 :(得分:1)
grep --invert-match --ignore-case cgs < filenames_list
答案 2 :(得分:1)
extglob
bash选项试试这个:
ls -ld $path/!(*[cC][gG][sS].csv)
看看
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
答案 3 :(得分:0)
以下内容可以帮助您:
ls |grep -iEv "cgs"
答案 4 :(得分:0)
使用grep的反转匹配:
grep -v 'cgs\|CGS' <filelist
或者,
ls | grep -v 'cgs\|CGS'