The UNIX and Linux Forums  

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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
calculate the date of next satureday of current date. rinku Shell Programming and Scripting 3 09-02-2008 08:05 PM
Get date and time for past 1 hour from current date spch2o Shell Programming and Scripting 5 08-29-2008 01:32 AM
Extracting date-time from file. skumar11 Shell Programming and Scripting 7 09-06-2007 01:45 PM
File date vs Current date trexlim Shell Programming and Scripting 4 05-04-2007 06:35 PM
how to give current date in file name? simurg11 UNIX for Dummies Questions & Answers 3 05-10-2005 06:09 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-26-2008
Registered User
 

Join Date: Aug 2007
Posts: 5
Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date.

$file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z


really appreciate any help.

thanks
mkneni
Reply With Quote
Forum Sponsor
  #2  
Old 03-26-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
m/(\d+)\./
Reply With Quote
  #3  
Old 03-26-2008
Registered User
 

Join Date: Mar 2008
Posts: 4
you can then use Date::Calc:elta_Days to compare file date with today's date.
Reply With Quote
  #4  
Old 03-26-2008
Registered User
 

Join Date: Aug 2007
Posts: 5
Thank you both. I am still lost. I am not talking about the mtime of the file. I need to extract date portion from the file name (which is in YYYYMMDD format) and compare it with the current date.
Reply With Quote
  #5  
Old 03-26-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Code:
if ($friendly_dancing_file_name =~ m/(\d+)\./) {
  print "oh goody, looks like the file's date is $1\n";
  print "abort, return, continue, are you sure?\n";
  <>;
}
If you don't know any Perl and would like for someone to write the script for you for free, now would be a good time to let us know. Did you look at the Date module's documentation, the Perl FAQ, and the FAQ for these forums? Date calculations are a frequently recurring topic and most questions you could imagine have already been asked and answered thoroughly.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 03:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0