I take it that 20111031 is the date of that log file. And it appears that the logging software starts a new log file each day? So, all you have to do is move the old log files to some archive directory if it is from yesterday. If that's not right, then please explain.

This type of string "20111031" is great as long as it has leading zeroes for the months and years as that can be used in a simple string comparison against the current date string.

So how to get the current date string?

#!/usr/bin/perl -w use strict; my ($year,$month,$day) = (gmtime(time))[5,4,3]; $year +=1900; $month +=1; my $date = sprintf("%4d%02d%02d", $year,$month,$day); print "date = $date\n"; #date = 20111031
Extract the date string from the filename using a regex, then use a simple string comparison and then move the file it if is less than today's date. Here's how to extract the date string..

#!/usr/bin/perl -w use strict; while (<DATA>) { #one of many, many ways to get the 8 digit date my ($date) = /(\d{8}).*.log$/; print "$date\n"; } =prints 20111031 // Oct 31, 2011 20110101 // Jan 01, 2011 =cut __DATA__ AAAA*20111031*.log AAAA*sfdaf*20110101*.log
I suppose from the formulation of the problem that you are thinking in terms of Windows wildcards and not UNIX regular expressions. Experiment with the above code and I think it will work for you. Report back if you have problems.

In reply to Re: Help in using backtick operator by Marshall
in thread Help in using backtick operator by manutd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.