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 2 Days Ago 08:05 PM
Get date and time for past 1 hour from current date spch2o Shell Programming and Scripting 5 1 Week Ago 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
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
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 (permalink)  
Old 03-26-2008
era era is online now
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,063
Code:
m/(\d+)\./
Reply With Quote
  #3 (permalink)  
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 (permalink)  
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 (permalink)  
Old 03-26-2008
era era is online now
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,063
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 UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:25 AM.


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

Content Relevant URLs by vBSEO 3.2.0