- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to remove date from filename
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2009 01:08 PM
07-16-2009 01:08 PM
pdstmbr_a.fdr.
The tricky part is that the MMDD on the filename is the previous day's date....
For example file create on July 17 would have the name of pdsptmbr_0716_a.fdr
Thanks for your time.....
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2009 01:39 PM
07-16-2009 01:39 PM
Solutioni m not able to get your question clearly..
anyway
if u want to change the name of yesterday's file to pdstmbr_a.fdr is easy.
mv pdsptmbr_[0-1][0-9][0-3][0-9]_d.fdr pdstmbr_a.fdr
this will change the name of the file with any date to pdstmbr_a.fdr
but you have to move the file which created today to some other folder then only you can create another one file with the same name rommorow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2009 03:31 PM
07-16-2009 03:31 PM
Re: How to remove date from filename
Perl makes this easy.
# cat .mknewname
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
my $oldname = shift or die "Filename expected\n";
my ( $first, $mon, $day, $last, $newname );
if ( $oldname =~ m{(.+_)(\d\d)(\d\d)(_.+)} ) {
$first = $1;
$mon = $2;
$day = $3;
$last = $4;
}
my $year = (localtime)[5];
my $epoch = timelocal( 0, 0, 0, $day, $mon - 1, $year ) - ( 60 * 60 * 24 );
( $day, $mon ) = ( localtime($epoch) )[ 3, 4 ];
printf "%s%02d%02d%s\n", $first, $mon + 1, $day, $last;
1;
...
Run as:
# ./mknewname pdsptmbr_0717_a.fdr
pdsptmbr_0716_a.fdr
The script formulates yesterday's date from what it finds in the filename passed. Transitions accross month boundries are handled.
# ./mknewname pdsptmbr_0301_a.fdr
pdsptmbr_0228_a.fdr
...which would be 0229 if the current year was a leap year.
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2009 03:47 PM
07-16-2009 03:47 PM
Re: How to remove date from filename
If you create one file like this per day, and
you rename it each day, then who cares what's
between the underscores?
bash$ echo 'pdsptmbr_0716_a.fdr' | sed -e 's/_.*_/_/'
pdsptmbr_a.fdr
> i m not able to get your question clearly..
A clearer explanation of why a very simple
solution is inadequate might be nice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2009 04:00 AM
07-17-2009 04:00 AM
Re: How to remove date from filename
Duh, I forgot to add the actual rename of your file. This version corrects that:
# cat ./myrename
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
my $oldname = shift or die "Filename expected\n";
my ( $first, $mon, $day, $last, $newname );
if ( $oldname =~ m{(.+_)(\d\d)(\d\d)(_.+)} ) {
( $first, $mon, $day, $last ) = ( $1, $2, $3, $4 );
}
else {
die "Filename format missing '_MMDD_'\n";
}
my $year = (localtime)[5];
my $epoch = timelocal( 0, 0, 0, $day, $mon - 1, $year ) - ( 60 * 60 * 24 );
( $day, $mon ) = ( localtime($epoch) )[ 3, 4 ];
$newname = sprintf "%s%02d%02d%s", $first, $mon + 1, $day, $last;
die "Can't rename '$oldname'\n" unless rename($oldname, $newname);
1;
...now simply run:
# ./myrename pdsptmbr_0717_a.fdr
...which renames 'pdsptmbr_0717_a.fdr' to ' pdsptmbr_0716_a.fdr'.
Regards!
...JRF...