删除带有"find"的数字的文件名.在OSX和GNU中 [英] Prune filename with digits with "find" in OSX and GNU

查看:119
本文介绍了删除带有"find"的数字的文件名.在OSX和GNU中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试搜索文件并修剪名称中带有数字的相似文件

I am trying to make a search on a file and prune similar ones with digits in the name

  • myfile.txt

来自

  • myfile_00_04_version.txt
  • myfile_00.txt

.

find -E . -iregex ".*myfile.*([^0-9]{1,})\.txt"

摆脱myfile_00.txt,但摆脱myfile_00_04_version.txt

gets rid of myfile_00.txt, but not of myfile_00_04_version.txt

我尝试了OSX查找和GNU查找,都无济于事.

I tried both OSX find and GNU find, to no avail.

推荐答案

第二个.*允许模式匹配myfile和后跟.txt的非数字之间的任何字符.您需要将其删除,然后使用

The second .* lets the pattern match any chars in between myfile and a non-digit followed with .txt. You need to remove it, and use

.*myfile[^0-9/]{1,}\.txt

请注意,[^0-9/]将匹配除数字和/之外的任何字符(以保留在文件名中).

Note that [^0-9/] will match any char but a digit and / (to stay within a file name).

或者,确保文件名以myfile开头:

Or, to make sure the file name starts with myfile:

(.*/)?myfile[^0-9/]{1,}\.txt

其中(.*/)?与可选的子字符串匹配,从路径的开始到最后一个/.

where (.*/)? matches an optional substring, from the start of the path up to the last /.

这篇关于删除带有"find"的数字的文件名.在OSX和GNU中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆