匹配可选模式与查找命令
我想将所有文件与典型的fortran文件扩展名与查找匹配。典型的扩展是.f .f .for .f90 .f90 .f90 .f95 .f95 .f95 .f03 .f03 .f03 .f08 .f08 .f08 .f15 .f15 .f15 .f15 .f18 .f18
我到目前为止尝试的是find * -Name“ * -Name” * * \。[ff] [0-9OO] [0-9rr]“
,尽管.f and .f和.f。为此,我必须制作[0-9OO]和[0-9rr]可选的,通常用“?”完成。但是,此查找 * -name“ * \。[ff] [0-9oo]?[0-9rr]?”
不适合我的find版本。
I want to match all files with a typical fortran file extension with find. Typical extensions are .f .F .for .FOR .f90 .F90 .f95 .F95 .f03 .F03 .f08 .F08 .f15 .F15 .f18 .F18
what I tried so far is find * -name "*\.[Ff][0-9Oo][0-9Rr]"
this works for all the mentioned extensions despite .f and .F. For that I have to make [0-9Oo] and [0-9Rr] optional which is usually done with "?". However, this find * -name "*\.[Ff][0-9Oo]?[0-9Rr]?"
does not work with my version of find.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用gnu
查找
,您可以使用该模式匹配完全匹配的字符串:
*\。
- 任何文本到最右边的。
。包括它[FF]
-f
或f
[0-9OO]?
- 可选数字,o
或o
[0-9rr]?
- 可选数字,r
或r
。您还可以使用仅仅环球模式使用非regex方法:
请注意,
*
Glob模式与任何文本匹配。在上一个解决方案中,它是一个量词,是一个使前面模式匹配零或更多次的操作员。另外,在Glog模式中,。
匹配字面的点,无需逃脱它。With a GNU
find
, you can useThe pattern matches a string that fully matches:
.*\.
- any text up to the rightmost.
including it[Ff]
-F
orf
[0-9Oo]?
- an optional digit,O
oro
[0-9Rr]?
- an optional digit,R
orr
.You can also use a non-regex approach using mere glob patterns:
Note that here, the
*
glob pattern matches any text. In the previous solution, it was a quantifier, an operator that makes the preceding pattern match zero or more times. Also, in glob patterns,.
matches a literal dot, no need to escape it.