Find fields based on date criterion

Hi All ,

I am trying to find some non empty files from a directory based on below conditions :
Files::

 SIZE  DATE          FILE 
 3679 Jan 25 23:59 belk_rpo_error_po9324892_01252014.log
   0    Jul 01 06:30 belk_rpo_error_po9324267_07012014.log
   0    Jul 20 05:50 belk_rpo_error_po9999992_07202014.log
 411  Jul 21 06:30 belk_rpo_error_po9999992_07212014.log
 742  Jul 21 07:30 belk_rpo_error_po9999991_07212014.log
4096 Jul 23 08:54 TEMP
   0   Jul 23 2014  belk_rpo_error_po9999991_07232014.log

My script takes a date range say 8 and it will fetch all the files between Current date to date which is 8 days ago.
if Current date is 23 Jul then files between 23 -15 Jul

  1. po9999992,po9999991 is the group numbers.

  2. Now if we take the example of po9999992 , we can see we have 2 files on Jul 20 and Jul 21 respectively. Jul 20 file is 0 KB . So I will take only Jul-21 file(latest file) which is non -zero size

  3. For po9999991 we can see we have 2 files on Jul 23 and Jul 21 .the latest file is 0 KB . So I will not take either of the 2 files.

Kindly give me some sample code.

You say you already have a script so what exactly are you asking for? A better way? Post your script.

yes a better way is all I am asking

Post your script. if you have something working, what exactly is the problem? What problem are you trying to solve?

Thanks for replying. I dont have any working script yet. I am trying to do it. Is it possible to do using find command?

I have already explained exactly what I am looking for.

---------- Post updated at 01:43 PM ---------- Previous update was at 01:39 PM ----------

My requirement If for the same po9999992 there is two files . One is older than the other with the older one being 0 KB then I will take the Non Zero Latest file.

and If for the same po9999992 there is two files . One is older than the other with the lastest one being 0 KB then I will NOT take either of them.

Your specification is far from clear. You could have provided some expected output. Nevertheless, try this:

find . -mtime -8 -ls |
awk     '       {split ($11, T, "[._]")
                 D=substr(T[5],5,4)substr(T[5],1,2)substr(T[5], 3, 2)
                 if (D>DAY[T[4]] && $7 > 0)
                                        {DAY[T[4]]=D; FN[T[4]]=$11}
                 else                   {delete DAY[T[4]];delete FN[T[4]]}
                }
         END    {for (i in DAY) print FN}
        '
belk_rpo_error_po9999992_07212014.log
belk_rpo_error_po9324892_01252014.log
1 Like

Thanks RudiC ..
Sorry for not being clearer with my requirement.

   3679 Jan 25 23:59 belk_rpo_error_po9324892_01252014.log
      0 Jul 01 06:30 belk_rpo_error_po9324267_07012014.log
      0 Jul 20 05:50 belk_rpo_error_po9999992_07202014.log
    411 Jul 21 06:30 belk_rpo_error_po9999992_07212014.log
    742 Jul 21 07:30 belk_rpo_error_po9999991_07212014.log
      0 Jul 23 2014  belk_rpo_error_po9999991_07232014.log


 

The columns are size,date,file name, the bold texts represents a particular Order_no. Now if we take the example of po9999992 it has 2 files on Jul 20 and Jul 21. For this Order_No there was a 0 KB file on Jul 20 but later it has some in it.(Jul 21 file). So I will take the Non Zero file that was created later for this order_no. i.e. belk_rpo_error_po9999992_07212014.log

Now if we take the example of po9999991 it has 2 files on Jul 21 and Jul 23. Although it created a Non Zero file on 21st Later it produced a 0 KB file. So If I see from my current date (I.e. 24th Jul) I don't have any use for Jul 21st file as later it was 0 KB. So I will discard both of them.

The other 2 files are discarded

    3679 Jan 25 23:59 belk_rpo_error_po9324892_01252014.log
      0 Jul 01 06:30 belk_rpo_error_po9324267_07012014.log
 

as they don't fall within my provided date range.

For example if Sysdate is 24th July and I want to fetch last 8 day's file , Start date would be 16th July and End date 24th July.

MY Final Output is like
411 Jul 21 06:30 belk_rpo_error_po9999992_07212014.log

Did you try to adapt my proposal?