Dmitry Starostin
Dmitry Starostin

Reputation: 187

Prune filename with digits with "find" in OSX and GNU

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

from

.

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

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

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

Upvotes: 2

Views: 50

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626758

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

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

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 /.

Upvotes: 2

Related Questions