I want to be able to loop through a list of files that match a particular pattern. I can get unix to list these files using ls and egrep with a regular expression, but I cannot find a way to turn this into an iterative process. I suspect that using ls is not the answer. Any help would be gratefully received.
My current ls command looks as follows:
ls | egrep -i 'MYFILE[0-9][0-9]([0][1-9]|1[0-2])([0][1-9]|[12][0-9]|[3][01]).dat'
I would expect the above to match:
- MYFILE160418.dat
- myFILE170312.DAT
- MyFiLe160416.DaT
but not:
- MYOTHERFILE150202.DAT
- Myfile.dat
- myfile.csv
Thanks,
Paul.
whileor afor. Use a counter as in the example -> tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.htmlxargs.ls | egrep -i 'MYFILE\d{6}\.dat'