Get date range between 2 date input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get date range between 2 date input
# 1  
Old 04-21-2009
Get date range between 2 date input

Hi Experts,

I have files name

report_20090416
report_20090417
report_20090418
report_20090420
report_20090421

I have 2 input from user
From Date: 20090417
To Date: 20090420
and I need to grep only those line in between. Output should be

report_20090417
report_20090418
report_20090420

Thanks,
# 2  
Old 04-21-2009
try this:

awk -F "_" -v st=20090417 -v ed=20090420 '$2 >= st && $2 <= ed{print}' filename


cheers,
Devaraj Takhellambam
# 3  
Old 04-21-2009
Quote:
Originally Posted by tanit
Hi Experts,

I have files name

report_20090416
report_20090417
report_20090418
report_20090420
report_20090421

I have 2 input from user
From Date: 20090417
To Date: 20090420
and I need to grep only those line in between. Output should be

report_20090417
report_20090418
report_20090420

Thanks,

Try this,
Variables i1 and i2 are inputs
Code:
$ echo $i1
20090417
 
$ echo $i2
20090420
 
$ cat file
report_20090416
report_20090417
report_20090418
report_20090420
report_20090421
 
$ awk -F"_" ' $2 >= '$i1' && $2 <= '$i2' {print}' file
report_20090417
report_20090418
report_20090420

# 4  
Old 04-21-2009
Thank you all for your help. It works.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date range

Dear all, how can I select in the file below only the files created between Aug 14 2014 and Feb 03 2015? EZA2284I -rw-r--r-- 1 30 8 356954 Aug 15 2014 file1 EZA2284I -rw-rw-r-- 1 30 8 251396 Feb 05 12:53 file2 EZA2284I -rw-rw-r-- 1 30 8 ... (3 Replies)
Discussion started by: simomuc
3 Replies

2. 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

3. Shell Programming and Scripting

Script to get previous date for the given input date..

hi all, need a script or command to get the previous date for the given input date... like in my script i will pass date as input parameter like 2014-12-01 and i want the output as previous date.. ie.. 2014-11-30 (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

4. Shell Programming and Scripting

Date listing in a date range

Solaris 10 ksh88 Sorry for re-hashing some of this, but I can't find a proper solution in the forums. Starting with /a/archive containing (on and on date formatted directories) 20060313 20080518 20100725 20121015 20060314 20080519 ... (1 Reply)
Discussion started by: moesplace
1 Replies

5. Shell Programming and Scripting

Get yesterdays Date for Input Date

Hi, I have been trying to get the yesterdays date for the Input date I pass. I know how to do for the current timestamp but how to do for the input date. Is there any way I can convert to epoch time and do manipulations and back to human readable date? Please help Thanks ... (1 Reply)
Discussion started by: abhi1988sri
1 Replies

6. UNIX for Advanced & Expert Users

Help with ksh script to list, then cp files from a user input date range

Hi, I'm quite new to ksh scripting, can someone help me with this. Requirements: I need to create a script that list the files from a user input date range. e. g. format of file: *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00*... (1 Reply)
Discussion started by: chococrunch6
1 Replies

7. Shell Programming and Scripting

Converting a date to friday date and finding Min/Max date

Dear all, I have 2 questions. I have a file with many rows which has date of the format YYYYMMDD. 1. I need to change the date to that weeks friday date(Ex: 20120716(monday) to 20120720). Satuday/Sunday has to be changed to next week friday date too. 2. After converting the date to... (10 Replies)
Discussion started by: 2001.arun
10 Replies

8. Shell Programming and Scripting

display Range of date depend on user input php

Hi, i am very new to php Is it possible to display Range of date depend on user input day example: user input 2 day start from 28/4/12 it will add 2 day from date of input so display should look like this 28/4/12 to 30/4/12 then from 30/412 user add another 4 date so will... (0 Replies)
Discussion started by: guidely
0 Replies

9. Shell Programming and Scripting

Search on date range of file based on user input

Hello I would like to ask for help with a script to search a directory that contains many log files and based on a users input after being prompted, they enter a date range down to the hour which searches the files that contain that range. I dont know how to go about this. I am hoping that the... (5 Replies)
Discussion started by: lostincashe
5 Replies

10. UNIX Desktop Questions & Answers

date range

I have a number of instances wher I need to run reports for the previous month and need to include the last months date range in the sql. I want to create a string which consists of the first and last dates of last month separated with an ' and ' ie for this month (Feb) I want it to say '01/01/10... (3 Replies)
Discussion started by: Niven
3 Replies
Login or Register to Ask a Question