Finding files with filename format

hi all,

i'm trying to find out how to show files having a particular format. i.e.

files
o570345.out
o5703451.out
XX_570345_1.RTF

so when i search for files using
ls *570345*

it shows all three files but actually i don't like to see the second file o5703451.out because 5703451 is different from 570345. how do i go about this?

thanks

egrep:

F=570345
echo *${F}* | grep -E '[^0-9]$F[^0-9]'
# ls *${F}* | grep -E '[^0-9]$F[^0-9]' # If the previous doesn't work
1 Like

the second code is good.

coz in first it will not show the desied result though those three file are a single line representation.
but the ls *${F}* is a three line representation of those three file before coming to grep.

welcome anytime,
Sanjay

1 Like
ls *[^0-9]570345[^0-9]*
1 Like

thank you all for your help.

just curious, what does the [^0-9] mean by appearing before and after?

[^0-9] - means there should be no numbers between 0 to 9 appear before and after your filename (570345)

2 Likes

thanks.