The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 11:23 AM
get Message from file within date range ambharish UNIX for Dummies Questions & Answers 2 06-29-2007 05:20 PM
Log File date compare for user defined range mojo24 Shell Programming and Scripting 0 05-05-2006 06:39 AM
date-extraction from a file in KSH homer_hn Shell Programming and Scripting 6 04-21-2006 01:51 AM
Need to print file names in a certain date range using ls Shamwari UNIX for Dummies Questions & Answers 2 10-08-2001 07:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-13-2006
ganapati's Avatar
ganapati ganapati is offline
Registered User
  
 

Join Date: Jul 2006
Location: Mysore
Posts: 125
Post 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
  #2 (permalink)  
Old 07-13-2006
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,414
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 (permalink)  
Old 07-13-2006
ganapati's Avatar
ganapati ganapati is offline
Registered User
  
 

Join Date: Jul 2006
Location: Mysore
Posts: 125
Exclamation 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


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


My Sincere Thanks to all.
Ganapati.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0