For Loop throwing error

Hello Gurus,
I am writing one script at linux.
The logic is

  1. There is a find command which will find some specific files daily [three files generating] and store at a variable [Working fine]
  2. Then echo that variable [Working fine].
  3. Now when I am trying to read the variable by using for loop it is throwing error as below:
    text cat: CKDT.dat: No such file or directory

===========
The script details are as below:
---------------

FILEPATH="/u10/archive/"
DTFILE=`find ${FILEPATH} -type f -mtime -1 -printf '%f %TH:%TM\n' | awk '$NF>"06:40" && $NF<"06:50" {print $1}'`
echo ${DTFILE}

for i in `cat ${DTFILE}`
do
echo ${i}
done

--------
Please suggest.

Thanks-
Pokhraj

Heya

What is the output of:

echo ${DTFILE}

The output of ${DTFILE]-- Its working fine.

Thanks-
Pokhraj

Unless there is a file named "It's working fine", then I doubt that loop is going to work.

1 Like

Does CKDT.dat exist in your current directory? Or in a subdirectory (where cat can't find it)? The %f format specifier prints just the file name, not any leading path elements.

Another approach:-

find ${FILEPATH} -type f -newermt "2015-07-10 06:40:00" ! -newermt  "2015-07-10 06:50:00" | while read file
do
        while read line
        do
                printf "%s\n", "$line"
        done < "$file"
done