Finding File Names Ending In 3 Random Numerical Characters

Hi, I have a series of files (upwards of 500) the filename format is as follows
CC10-1234P1999.WGS84.p190
each of this files is in a directory named for the file but excluding the extension.

Now the last three numeric characters, in this case 999, can be anything from 001 to 999, I need to move some of them to a seperate directory, the ones I need to move will be within a defined range, eg I would want to move everything from the file ending in 005 to the file ending in 155.
Any thoughts ?

try:

 echo **/* |xargs -n1 |while read line
do
filenum=`echo $line |grep -Po '([0-9]){3}(?=\.\D)'` 
if [ $filenum -ge 5 ] && [ $filenum -le 155 ]
then
mv $line new_directory
fi
done
1 Like

Thanks mate, do youthink that could be done just using find to get all the .p190 files then setting variables to get the 005 to 155 files ?

if the filename has the unifom format as *.*.*, you can try:

 echo **/*.*.p190 |xargs -n1 |while read line
do
filenum=`echo $line |grep -Po '([0-9]){3}(?=\.\D)'` 
if [ $filenum -ge 5 ] && [ $filenum -le 155 ]
then
mv $line new_directory
fi
done

if not, try:

 echo **/* |xargs -n1 |grep '\.p190$'|while read line
do
filenum=`echo $line |grep -Po '([0-9]){3}(?=\.\D)'` 
if [ $filenum -ge 5 ] && [ $filenum -le 155 ]
then
mv $line new_directory
fi
done