Shell script help to eliminate files of todays date

Hi
I am very new to shell scripting and have written a script (below).
However the directory I am searching will contain a file with a .trn extension each day which I want to eliminate.
Each day the file extension overnight will change to trx, if this fails I want to know.
Basically what I want to do is add to the script to eliminate any files with a TRN extension for todays date, can anyone help me please.
I am using unix version 11.11
thanks in advance. :slight_smile:

for DIRECTORY in $(awk '{print $1}' /appl/pro/eftids)
  do
    #ls -t|head ${DIRECTORY}/trans1|grep -v "TRZ"|grep -v "TRX$"}
    if [ $(ls -t ${DIRECTORY}/trans1|head|grep -v "TRZ"|grep -v "TRX$"|wc -l) -gt 0 ]
    then
    echo !!LOG ERROR ${DIRECTORY}/trans1 $(ls -t ${DIRECTORY}/trans1|head|grep -v "TRZ"|grep -v "TRX$")
    else
      echo "${DIRECTORY}/trans1 Directory OK"
    fi
  done

Not bad for a first try. first, learn about BB "code" tags. That helps a bit!

Anyway, it turns out there's a UNIX utility to do what you need. It's called "find".

awk '{ print $1 }' /appl/pro/eftids | 
while read DIRECTORY; do 
  find $DIRECTORY -type f -name "*.TRN" -print 
done > /tmp/found-trn-files.$$

# You can put this inside or outside the above loop. 
if ! [ -s /tmp/found-trn-files.$$ ]; then
  echo '!!LOG ERROR. The following files were not converted:'
  cat /tmp/found-trn-files.$$
fi
# cleanup
rm /tmp/found-trn-files.$$

The other way is to have a loop-within-a-loop, like this;

awk '{ print $1 }' /appl/pro/eftids | 
while read DIRECTORY; do 
  /bin/ls -1 $DIRECTORY/trans1/ |
  while read FILE ; do 
     if ! echo $FILE |grep '\.TR[XZ]$' &>/dev/null  ; then
        echo '!!LOG ERROR .... ' $FILE in $DIRECTORY
     fi
  done
done

That's fantastic. Thanks for your help and advice. :):b: