PDA

View Full Version : Find/regex (find files that contain numbers)



altonbr
May 12th, 2010, 03:12 PM
I'm pretty new to regexs, let along find's implementation of how to use regexs.

I'm looking to find all files that contain numbers, not just end in them.

Currently, my regex just returns files that end in a number...

find . -regex ".*[0-9]+"Any advise?

I guess this could work:

find . | egrep '0|1|2|3|4|5|6|7|8|9'

ja660k
May 12th, 2010, 04:02 PM
find .
will return all files and files in subfolders of your current working directory...
if thats what you want fine...

so your regex,

\d matches any digit,
\d is the same as [0-9]

but short :-)
That being said, egrep regex engine doesnt support \d (i think)

so youll have


ls | egrep '[0-9]'

and that returns files & dirs with a digit in them.


ls | egrep '^[0-9]'

will return files/folders where a number is at the start


ls | egrep '[0-9]$'

will return files/folders with a number at the end.

happy regex'ing

schauerlich
May 12th, 2010, 07:51 PM
schauerlich@inara:~/clean$ ls -R
3three bar foo foobar one two2

./foo:
4four4 five5five
schauerlich@inara:~/clean$ find . | egrep "[0-9]"
./3three
./foo/4four4
./foo/five5five
./two2
schauerlich@inara:~/clean$

hannaman
May 12th, 2010, 08:08 PM
find . -name "*[0-9]*" doesn't work?

schauerlich
May 12th, 2010, 08:30 PM
find . -name "*[0-9]*" doesn't work?

That's much too simple an efficient. :) (d'oh)