[英]Exact match file extension filter using grep
I am working on running cat on all files with JS/JSX/SCALA extensions, I've tried the following我正在使用 JS/JSX/SCALA 扩展名在所有文件上运行 cat,我尝试了以下
git ls-files | grep ".[js|jsx|scala]$"
git ls-files | grep ".*js|jsx|scala"
The end result will eventually look like this最终结果最终将如下所示
git ls-files | grep -e ".*[js|jsx|scala]$" | xargs cat | wc -l
But I keep getting more files like yaml, yml但我不断收到更多文件,例如 yaml, yml
Use a group:使用组:
git ls-files | grep -E '\.(js|jsx|scala)$'
The \.(js|jsx|scala)$
pattern matches a dot and then js
, jsx
or scala
and then the end of string. \.(js|jsx|scala)$
模式匹配一个点,然后是js
、 jsx
或scala
,然后是字符串的结尾。
Mind the -E
option enabling POSIX ERE compliance.注意启用 POSIX ERE 合规性的
-E
选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.