Regular Expression in Date ls command

Hi,

I have got a problem in a regular expression with a file name containing date. I am using a regular to display the file in ls, but by using the same it gives me file name does not exist.

--## File exist when I do ls.

ls
amey_in20131018.csv

--## File name not showing when I use the regexp

ls -lrt amey_in[0-9]{8}.csv
amey_in[0-9]{8}.csv: No such file or directory

Can anybody please let me know what is wrong in my expression ?

Regards,
Amey

Try piping output of ls command to grep. You also need to escape the curly brackets.

ls -l | grep 'amey_in[0-9]\{8\}.csv'

It looks like mjf gave you a workaround for your problem, but didn't answer your question. In the command:

ls -lrt amey_in[0-9]{8}.csv

amey_in[0-9]{8}.csv is a shell pathname matching expression; not a regular expression. In shell pathname matching patterns, there is not way to specify a number of times to match the previous (sub)pattern. This pathname matching pattern would only match filenames that start with the string amey_in followed by a single decimal digit followed by the string {8}.csv .

PS Another way to do this would be to use:

ls -lrt amey_in[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].csv

Thanks Don,

So according to you there is no specific way to find number in times.

Regards,
Amey

That is not at all what I said. I said that [0-9]{8} is not the way to look for eight decimal digits in a filename using shell pathname patterns. If you want to match eight decimal digits in a filename, mjf showed you a way to use ls and a regular expression in grep; and I showed you a way to use ls with a longer pathname matching pattern.

Try this

ls -lrt | grep -E amey_in[0-9]{8}.csv