Need help in a small script

Hi all,

I have a file of the following format -

EXPRPT:SCN:1.1706E+10:SEQ_START:121652:SEQ_END:121664:0
( This file name is variable and changes daily)

Now in the same directory I have another set of files of the format -

EXPRPT.log.0001.0000121669

Now what I am trying to do is to

  1. Parse the first file name and Get the number 121652 from the first file and then DELETE all the files of type EXPRPT.log.* where 6-7 digits of EXPRPT.log.* are lesser than number extracted from first file.

For example -

Let us say the following files are there -

EXPRPT.log.0001.0000121649
EXPRPT.log.0001.0000121651
EXPRPT.log.0001.0000121669
EXPRPT.log.0001.0000121670

Then only following files should be deleted as number 121652 is higher than numbers in these files.

EXPRPT.log.0001.0000121649
EXPRPT.log.0001.0000121651

Thanks for all your help.
Regards

You should be able to modify the below code to suit your specific purposes

FILE="EXPRPT:SCN:1.1706E+10:SEQ_START:121652:SEQ_END:121664:0"

NUM=`echo $FILE | cut -d':' -f 5`

for file in `ls EXPRPT*`
do
  NUM2=`echo $file | cut -d'.' -f 4`
  if [ $NUM2 -lt $NUM ]
  then
    echo Removing $file
    rm -f $file
  fi
done

Thanks a lot.

Tested it in one scenario. Works fantastically.

Regards