Grepping the data between 2 date ranges


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grepping the data between 2 date ranges
# 8  
Old 03-14-2018
Why (i.e. by WHAT logic) is 3/4/2016 file2 part of the result output when end date is 1/1/2016?
# 9  
Old 03-14-2018
I am sorry..I have typed wrongly.

The output should be

Code:
4/3/2014  file4
6/6/2015  file5

# 10  
Old 03-14-2018
Why the reversal of lines?

Try
Code:
awk -F"[ /]" -vSTART="1/1/2014" -vENDDT="1/1/2016" '
function MLDT(D, M, Y)  {return Y * 1E4 + M * 100 + D
                        }
BEGIN   {split (START, TMP)
         ST = MLDT(TMP[1], TMP[2], TMP[3])
         split (ENDDT, TMP)
         EN = MLDT(TMP[1], TMP[2], TMP[3])
        }
MLDT($1, $2, $3) >= ST &&
MLDT($1, $2, $3) <= EN
' file
6/6/2015  file5
4/3/2014  file4

# 11  
Old 03-14-2018
Hi RudiC,

Thank you. I will try this code. and keep you posted further.
# 12  
Old 03-14-2018
A bit simplified:
Code:
awk -vSTART="1/1/2014" -vENDDT="1/1/2016" '
function MLDT(DT)       {split (DT, TMP, "/")   
                         return TMP[3] * 1E4 + TMP[2] * 100 + TMP[1]
                        }
BEGIN   {ST = MLDT(START)
         EN = MLDT(ENDDT)
        }
MLDT($1) >= ST &&
MLDT($1) <= EN
' file

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Search files between date ranges - Ctime usage

Hello, I am a noob and need some help. I am trying to find files created between a date range. For Example: These are files in directory. -rw-r--r-- 1 user staff 6 May 8 09:43 file1.txt -rw-r--r-- 1 user staff 6 May 8 09:43 file2.txt -rw-r--r-- 1 user... (8 Replies)
Discussion started by: r@v!7*7@
8 Replies

2. Programming

Derivation of values falling on date ranges

Hi Guys, I am having below tables used in oracle bal ID BALANCE BAL_DATE 1 -11.71 01-JAN-05 00.00.00 1 -405.71 02-JAN-05 00.00.00 1 -760.71 03-JAN-05 00.00.00 ref_table PRODUCT EFF_FROM_DATE EFF_TO_DATE TYPE MIN_AMT MAX_AMT CHARGE 12 01-JAN-05 00.00.00 01-JAN-06... (6 Replies)
Discussion started by: rohit_shinez
6 Replies

3. Shell Programming and Scripting

Grepping data using awk

Hello, I have a data in file 1 2000000024776 2000000026979 2000000033355 2000000036309 2000000041291 2000000042679 2000000067221 and in file 2 its like this 2000000024776 16 2000000026979 16 2000000033355 16 (2 Replies)
Discussion started by: mirwasim
2 Replies

4. Shell Programming and Scripting

Help with grepping data from a text file

Hello, I have a text file which contains a list of strings which I want to grep from another file where these strings occur and print out only these lines. I had earlier used the grep command where File1 was the file containing the strings to be grepped (Source File) and File2 the Target File... (4 Replies)
Discussion started by: gimley
4 Replies

5. Shell Programming and Scripting

getting files between specific date ranges in solaris

hi ! how can i get files in a directory between certain date ranges ? say all files created/modified between Jan24 - Jan31 thanks (10 Replies)
Discussion started by: aliyesami
10 Replies

6. Shell Programming and Scripting

Grepping Date Variable

Hello, I would like for the user to input the date for a particular log file, then have the input sent to a variable, which is then used via grep to extra the logs for the specific date the user request. I did some searching, but I still don't understand why I'm not seeing any result. ... (4 Replies)
Discussion started by: ravzter
4 Replies

7. Linux

search on weblogic logs with date time ranges

Hi All, The developers want me to search and capture the weblogic log, you know this big logs of htmls. They want to me to have ranges on the date and time. Like from "2010-01-20 14:04:46,186" to "2010-01-20 15:00:12,490" I can only do this, cat /usr/local/bea/logs_prod1/debug.log... (1 Reply)
Discussion started by: itik
1 Replies

8. Shell Programming and Scripting

search on weblogic logs with date time ranges 2

Hi All, The developers want me to search and capture the weblogic log, you know this big logs of htmls. They want to me to have ranges on the date and time. Like from "2010-01-20 14:04:46,186" to "2010-01-20 15:00:12,490" I can only do this, cat /usr/local/bea/logs_prod1/debug.log |... (1 Reply)
Discussion started by: itik
1 Replies

9. Shell Programming and Scripting

date ranges

Hi, Please anyone help to achive this using perl or unix scripting . This is date in my table 20090224,based on the date need to check the files,If file exist for that date then increment by 1 for that date and check till max date 'i.e.20090301 and push those files . files1_20090224... (2 Replies)
Discussion started by: akil
2 Replies

10. Shell Programming and Scripting

find command: various date ranges

Hi, I have writtena script that will recursivly go into subdirecotries and report out what files there are in there that have not been accessed over various date ranges. I do this using a number of find commands: find . -path './.snapshot' -prune -o -type f -atime -8 find... (4 Replies)
Discussion started by: littleIdiot
4 Replies
Login or Register to Ask a Question