Report file extraction based on Date range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Report file extraction based on Date range
# 1  
Old 07-13-2006
Java Report file extraction based on Date range

Hi all,

Iam writing a script, which will extract all the files from Start_Date to End_Date. Files are date stamped as YYYYMMDD. For ex:

Start_Date='20051001'
End_Date='20060331'

extract files such as........

ramp_20050810.rpt
ramp_20050915.rpt
ramp_20051001.rpt
ramp_20051010.rpt
ramp_20051114.rpt
ramp_20051218.rpt
ramp_20060112.rpt
ramp_20060310.rpt

ramp_20060417.rpt
ramp_20050530.rpt

I've tried with so many options, and struggled with date increments and comparisions. I dont have much experience in shell scripting but I love it.

Any help will be much appreciated.

Many Thanks and Regards,
Ganapati Smilie
# 2  
Old 07-13-2006
you can do something like this :
Code:
Start_Date='20060701'
End_Date='20060715'
Prefix='ramp_'
Suffix='.rpt'

ls  ${Prefix}*${Suffix} 2>/dev/null |
while read file
do
   datestamp=`echo ${file} | sed -e "s/^${Prefix}//; s/${Suffix}\$//"`
    if [ $datestamp -ge ${Start_Date} -a ${datestamp} -le ${End_Date} ]
   then
      echo "Extract file $file"
   else
      echo "Ignore file $file"
   fi
done

Jean-Pierre.
# 3  
Old 07-13-2006
Error Amazing !!!!! It is working ?

Thanks for your help aigles,

I found out a short way to do this from one of the resource.

ls -lrt | awk '$9 ~ /20051001/ , $9 ~ /20060331/' | awk '{print $9}'

Amazingly it is working fine for my requirement. I can able to find the files between the Start_Date and End_Date which is date stamped with the file names.

Start_Date='20051001'
End_Date='20060331'

col1 col2 col3 col4 col5 col6 col7 col8 ramp_20050810.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20050819.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20050930.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20051001.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20051020.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20051119.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20051216.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20051219.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20060101.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20060230.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20060310.rpt

col1 col2 col3 col4 col5 col6 col7 col8 ramp_20060420.rpt
col1 col2 col3 col4 col5 col6 col7 col8 ramp_20060430.rpt


above script extracting the filenames correctly as:
ramp_20051001.rpt
ramp_20051020.rpt
ramp_20051119.rpt
ramp_20051216.rpt
ramp_20051219.rpt
ramp_20060101.rpt
ramp_20060230.rpt
ramp_20060310.rpt


Smilie Can any one explain this command that how it is able to select between these two date ranges !!!!!!???????


My Sincere Thanks to all.
Ganapati.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with tag value extraction from xml file based on a matching condition

Hi , I have a situation where I need to search an xml file for the presence of a tag <FollowOnFrom> and also , presence of partial part of the following tag <ContractRequest _LoadId and if these 2 exist ,then extract the value from the following tag <_LocalId> which is "CW2094139". There... (2 Replies)
Discussion started by: paul1234
2 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

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

4. Shell Programming and Scripting

copy range of lines in a file based on keywords from another file

Hi Guys, I have the following problem. I have original file (org.txt) that looks like this module v_1(.....) //arbitrary number of text lines endmodule module v_2(....) //arbitrary number of text lines endmodule module v_3(...) //arbitrary number of text lines endmodule module... (6 Replies)
Discussion started by: kaaliakahn
6 Replies

5. Shell Programming and Scripting

Search for a specific data in a file based on a date range

Hi, Currently I am working on a script to automate the process of converting the log file from binary into text format. To achieve this, partly I am depending on my application’s utility for this conversion and the rest I am relying on shell commands to search for directory, locate the file and... (5 Replies)
Discussion started by: svajhala
5 Replies

6. Shell Programming and Scripting

Date and time range extraction via Awk or analysis script?

Hello does anyone know of an awk that will extract log file entries between a specific date and time range, eg: awk '/15\/Dec\/2010:16:10:00/, /15\/Dec\/2010:16:15:00/' access_log but one that works? Or a free command line log file analysis tool/script? I'd like to be able to view... (2 Replies)
Discussion started by: competitions
2 Replies

7. Shell Programming and Scripting

Need script to select multiple files from archive directory based on the date range

hi all, here is the description to my problem. input parameters: $date1 & $date2 based on the range i need to select the archived files from the archived directory and moved them in to working directory. can u please help me in writing the code to select the multiple files based on the... (3 Replies)
Discussion started by: bbc17484
3 Replies

8. Shell Programming and Scripting

display the file with in the date range

Hi All, I want a shell script which can display the file with in the date range. For Example I have 15 files with the following format abc_01-01-2009.txt to abc_15-01-2009.txt. Now I want to have the files between 4th of jan to 12th files. How can I acheive this. Advance... (1 Reply)
Discussion started by: fareed_do
1 Replies

9. UNIX for Dummies Questions & Answers

get Message from file within date range

Hi All, I am a java devloper putting my hands on shell scripts. Honestly it sounds coool and interesting Presently I got stuck with the following requirement. Get the messages from file. The messages in the file are as follows: date|message1 date|message2 . . . date is of... (2 Replies)
Discussion started by: ambharish
2 Replies

10. Shell Programming and Scripting

date-extraction from a file in KSH

Hi, everyone, Now I have a ".csv" file and I want to extract a string-like date value from the file, say, it is in the 2nd row of the file and it is in the fixed context like: " This is the file title, //Row 1 The lastest update happened on: 10-Mar-2006 //Row2 ....//other irrelavent rows "... (6 Replies)
Discussion started by: homer_hn
6 Replies
Login or Register to Ask a Question