我的LIST文件中有很多行,并且只想列出名称不以“ git”开头(或包含)的行。
到目前为止,我有:
cat LIST | grep ^[^g]
但我想要这样的东西:
#not starting by "git"
cat LIST | grep ^[^(git)]
#not containing "git"
cat LIST | grep .*[^(git)].*
但这是不正确的。我应该使用什么正则表达式?
使用grep
在这种情况下与-P
选项,它解释图案作为一个Perl的正则表达式
grep -P '^(?:(?!git).)*$' LIST
正则表达式说明:
^ the beginning of the string
(?: group, but do not capture (0 or more times)
(?! look ahead to see if there is not:
git 'git'
) end of look-ahead
. any character except \n
)* end of grouping
$ before an optional \n, and the end of the string
使用find
命令
find . \! -iname "git*"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句