Perl: Extracting date from file name and comparing with current date

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: Extracting date from file name and comparing with current date
# 1  
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.

# 2  

# 3  
you can then use Date::Calc:Smilieelta_Days to compare file date with today's date.
# 4  
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.
# 5  
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.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #352
Difficulty: Easy
Unix was created 25 years before Linux.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace date in file every day with current date

I Have text like XXX_20190908.csv.gz need to replace Only date in this format with current date every day Thanks! (1 Reply)
Discussion started by: yamasani1991
1 Replies

2. UNIX for Beginners Questions & Answers

“sed” replace date in text file with current date

We want to call a parameter file (.txt) where my application read dynamic values when the job is triggered, one of such values are below: abc.txt ------------------ Code: line1 line2 line3 $$EDWS_DATE_INSERT=08-27-2019 line4 $$EDWS_PREV_DATE_INSERT=08-26-2019 I am trying to write a... (3 Replies)
Discussion started by: pradeepp
3 Replies

3. Shell Programming and Scripting

Subtract a file's modification date with current date

SunOS -s 5.10 Generic_147440-04 sun4u sparc SUNW,SPARC-Enterprise Hi, In a folder, there are files. I have a script which reads the current date and subtract the modification date of each file. How do I achieve this? Regards, Joe (2 Replies)
Discussion started by: roshanbi
2 Replies

4. Shell Programming and Scripting

Comparing the dates with the current date in perl scripting

Hi i have a file containg dates likebelow 4/30/2013 3/31/2013 4/30/2013 4/16/2013 4/30/2013 4/30/2013 5/30/2013 5/30/2013 4/30/2013 5/30/2013 5/30/2013 3/31/2013 now i want to compare the above dates with current date and i want to display the difference . (10 Replies)
Discussion started by: siva kumar
10 Replies

5. Shell Programming and Scripting

Fetch date of 7 years back from current date in Perl

$beginDate = substr(DateCalc("today", "-7Days"),0,8); This fetches the date 7 days back Can I fetch the date before 7 years from todays date in Perl using same syntax Use code tags, see PM. (3 Replies)
Discussion started by: parthmittal2007
3 Replies

6. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

7. UNIX for Dummies Questions & Answers

Comparing two files with datestamp to current date

Hi, I am new to unix and I am stuck on how to compare two .zip file with date stamp in my directory. I need to compare out of the two file which is oldest to current date and unzip it after that done continue to unzip the second zip file. Thanks for your help. (5 Replies)
Discussion started by: lilvi3tboix1
5 Replies

8. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

9. Shell Programming and Scripting

Comparing current date

Hi, I have start date and end date in the following format. I need to check the current date is greater than the start date and less than the end date. if i use the command date --date "Tue 6:00 AM", it takes next Tues day not the current week's Tues day. Is there a way to get the current Tues... (9 Replies)
Discussion started by: bharathappriyan
9 Replies

10. Linux

Comparing the file drop date with todays date

Daily one file will dropped into this directory. Directory: /opt/app/jt/drop File name: XXXX_<timestamp>.dat.gz I need to write a script which checks whether the file is dropped daily or not. Any idea in the script how can we compare timestamp of the file to today's date?? (3 Replies)
Discussion started by: Rajneel
3 Replies

Featured Tech Videos