Pbu
Pbu

Reputation: 35

How to search for numbers in filename/data in shell script

I have 10 files in a folder. All with similar pattern with text and number:

ABCDEF20141010_12345.txt
ABCDEF20141010_23456.txt
ABCDEF20141010_34567.txt
...

I need to process these files in a loop.

for filename in `ls -1 | egrep "ABCDEF[0-9]+\_[0-9]+.txt"`
do
  <code>
done

Above egrep code, is not going inside the loop. Can you please help me in modifying this search?

Upvotes: 2

Views: 42

Answers (1)

chaos
chaos

Reputation: 9312

You don't have to use ls and grep. It's working with shell-only functionalities:

for filename in ABCDEF[0-9]*_[0-9]*.txt
do
  echo $filename
  #do whatever
done

Upvotes: 1

Related Questions