Finiding filenames with specific index string

Hi All,

I have a file (Names.txt) and the contents of the file is give below.

$ cat Names.txt
FF313207008.txt
FF223207007.txt
FF143207006.txt
FF372150600.txt
FF063407005.txt
FF063307005.txt
$

From these given file names I want to find the files which has the 6th index value as 2. So the needed out put will be as below.

FF313207008.txt
FF223207007.txt
FF143207006.txt

Please help me if there is any command to do that.

Thanks for your help.

Cheers,
Krish

egrep '^.....2' Names.txt

Hi.

sed -n "/.....2/p" file4 
FF313207008.txt
FF223207007.txt
FF143207006.txt
 
or
 
sed -n "/.\{5\}2/p" file4
FF313207008.txt
FF223207007.txt
FF143207006.txt

( or grep :wink: )

If you don't put a ^ in front of your regex you will also match:

FF313000207011118.txt
FF223100022207007.txt
FF114300999207006.txt

Yes, of course. Good point, thank you.

In any case the grep solution's the simplest one.

So easy to overlook the simple ones!

Hi Neo,

Thanks for your help. It worked well.

Hi Scott,

Thanks for your help. That also worked well.

As you said, i used egrep, as it is the simple one.

Thanks again.
Krish.