drbunsen
drbunsen

Reputation: 10679

How to find files in a directory using grep with wildcards?

I have several hundred files with file names such as: 20110404_091415-R1-sometext

Another file name might be named: 20110404_091415-R1.2-sometext

What I would like to do is use the Unix grep tool in the terminal to find files that start with 2011 and also contain -R1 within the file name. Unfortunately, I have no idea to find files that satisfy both these criteria. I have tried to figure out a regex that would match this, but I am only a beginner programmer. Can anyone help please? Thanks in advance for your time.

Upvotes: 0

Views: 8635

Answers (3)

kurumi
kurumi

Reputation: 25599

Just to find files, you can use ls 2011*R1* or echo 2011*R1*. To do something to files, use a loop (generally)

for file in 2011*R1*
do
   ....
done

Upvotes: 0

Aadith Ramia
Aadith Ramia

Reputation: 10329

why even use grep? I think ls 2011*R1* should suffice..

Upvotes: 3

Jean-Bernard Jansen
Jean-Bernard Jansen

Reputation: 7872

ls | grep "^2011.*-R1.*"

Should do the job

Upvotes: 0

Related Questions