Find fields based on date criterion


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find fields based on date criterion
# 1  
Old 07-23-2014
RedHat 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::

Code:
 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.

Last edited by Don Cragun; 07-23-2014 at 01:34 PM.. Reason: Add CODE tags.
# 2  
Old 07-23-2014
You say you already have a script so what exactly are you asking for? A better way? Post your script.
# 3  
Old 07-23-2014
yes a better way is all I am asking
# 4  
Old 07-23-2014
Post your script. if you have something working, what exactly is the problem? What problem are you trying to solve?
# 5  
Old 07-23-2014
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.
# 6  
Old 07-23-2014
Your specification is far from clear. You could have provided some expected output. Nevertheless, try this:
Code:
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[i]}
        '
belk_rpo_error_po9999992_07212014.log
belk_rpo_error_po9324892_01252014.log

This User Gave Thanks to RudiC For This Post:
# 7  
Old 07-24-2014
Thanks RudiC ..
Sorry for not being clearer with my requirement.

Code:
   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
Code:
    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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find the files based on date from filelist

Hi All, I have a filelist which contains the "ls" output, i want to extract the filenames written in this files based on date. I know i can run loop and extract the file but i want to avoid it. also there is find command which can be used on directory i.e. find . -type f -newermt "2019-09-25"... (3 Replies)
Discussion started by: kumarinfa
3 Replies

2. UNIX for Beginners Questions & Answers

Find and copy .zip file based on today's date

Hi Team, I'm new to unix and i have a requirement to copy or move files from one directory to another based on current date mentioned in the .zip file name. Note that i need to copy only the recent zip file. please help me with the code i tried the code as: #! /usr/bin/sh find... (3 Replies)
Discussion started by: midhun3108
3 Replies

3. Shell Programming and Scripting

awk sort based on difference of fields and print all fields

Hi I have a file as below <field1> <field2> <field3> ... <field_num1> <field_num2> Trying to sort based on difference of <field_num1> and <field_num2> in desceding order and print all fields. I tried this and it doesn't sort on the difference field .. Appreciate your help. cat... (9 Replies)
Discussion started by: newstart
9 Replies

4. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

5. UNIX for Dummies Questions & Answers

Looking for command line to find dirs based on size and date

Hi, My first time on this site, please excuse me if I've come to the wrong forum. I'm fairly new to Unix/Linux and hoping you can help me out. I'm looking for a command line that will return a list of directories that are larger than 50M and older than 2 days. I thought it may be... (6 Replies)
Discussion started by: Wisconsingal
6 Replies

6. Shell Programming and Scripting

Find the latest file based on the date in the filename

Hi, We've a list of files that gets created on a weekly basis and it has got a date and time embedded to it. Below are the examples. I want to find out how to get the latest files get the date and time stamp out of it. Files are PQR123.PLL.M989898.201308012254.gpg... (1 Reply)
Discussion started by: rudoraj
1 Replies

7. Shell Programming and Scripting

Find and count unique date values in a file based on position

Hello, I need some sort of way to extract every date contained in a file, and count how many of those dates there are. Here are the specifics: The date format I'm looking for is mm/dd/yyyy I only need to look after line 45 in the file (that's where the data begins) The columns of... (2 Replies)
Discussion started by: ronan1219
2 Replies

8. Shell Programming and Scripting

Find and copy files based on todays date and search for a particular string

Hi All, I am new to shell srcipting. Problem : I need to write a script which copy the log files from /prod/logs directory based on todays date like (Jul 17) and place it to /home/hzjnr0 directory and then search the copied logfiles for the string "@ending successfully on Thu Jul 17". If... (2 Replies)
Discussion started by: mail.chiranjit
2 Replies

9. Shell Programming and Scripting

Find duplicate based on 'n' fields and mark the duplicate as 'D'

Hi, In a file, I have to mark duplicate records as 'D' and the latest record alone as 'C'. In the below file, I have to identify if duplicate records are there or not based on Man_ID, Man_DT, Ship_ID and I have to mark the record with latest Ship_DT as "C" and other as "D" (I have to create... (7 Replies)
Discussion started by: machomaddy
7 Replies

10. UNIX for Dummies Questions & Answers

Please help me to find out maximum value of a field based on grouping of other fields.

Please help me to find out maximum value of a field based on grouping of other fields, as we do in SQL. Like in SQL if we are having below records : Client_Name Associate_Name Date1 Value C1111 A1111 2012-01-17 10 C1111 A1111 ... (1 Reply)
Discussion started by: KamalKumarKalra
1 Replies
Login or Register to Ask a Question