Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Grepping the data between 2 date ranges

Tags
date, date range, shell scripting, shell scripts

👤 Login to reply

 
Thread Tools Search this Thread
# 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

The Following User Says Thank You to RudiC For This Useful Post:
kumar85shiv (03-14-2018)
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search files between date ranges - Ctime usage r@v!7*7@ UNIX for Beginners Questions & Answers 8 05-13-2017 03:32 PM
Derivation of values falling on date ranges rohit_shinez Programming 6 03-01-2016 10:11 AM
Grepping data using awk mirwasim Shell Programming and Scripting 2 04-04-2013 02:03 PM
Help with grepping data from a text file gimley Shell Programming and Scripting 4 09-05-2012 10:37 PM
getting files between specific date ranges in solaris aliyesami Shell Programming and Scripting 10 02-02-2012 06:35 AM
Grepping Date Variable ravzter Shell Programming and Scripting 4 05-26-2010 08:25 AM
search on weblogic logs with date time ranges itik Linux 1 01-27-2010 05:53 PM
search on weblogic logs with date time ranges 2 itik Shell Programming and Scripting 1 01-27-2010 05:19 PM
date ranges akil Shell Programming and Scripting 2 07-15-2009 05:50 AM
find command: various date ranges littleIdiot Shell Programming and Scripting 4 10-24-2008 10:33 AM


All times are GMT -4. The time now is 11:51 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password