<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eddie On Everything &#187; perl</title>
	<atom:link href="http://www.eddieoneverything.com/category/perl/feed" rel="self" type="application/rss+xml" />
	<link>http://www.eddieoneverything.com</link>
	<description>Tips &#38; tricks on things that interest me</description>
	<lastBuildDate>Wed, 11 Jan 2012 08:29:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rotating Backup Directories using cp -al (hardlinks) to Save Disk Space</title>
		<link>http://www.eddieoneverything.com/linux/rotating-backup-directories-using-cp-al-hardlinks-to-save-disk-space.php</link>
		<comments>http://www.eddieoneverything.com/linux/rotating-backup-directories-using-cp-al-hardlinks-to-save-disk-space.php#comments</comments>
		<pubDate>Sun, 15 Nov 2009 20:13:16 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[system administration]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/?p=356</guid>
		<description><![CDATA[The copy command &#8220;cp -al&#8221; found on all versions of Unix/Linux creates what&#8217;s called a &#8220;hard link&#8221; to a file. The nice thing about this command is that it doesn&#8217;t create an actual copy of the file on disk &#8211; instead, it creates a &#8220;link&#8221; or pointer to the file data on the disk.  [...]]]></description>
			<content:encoded><![CDATA[<p>The copy command &#8220;cp -al&#8221; found on all versions of Unix/Linux creates what&#8217;s called a &#8220;hard link&#8221; to a file. The nice thing about this command is that it doesn&#8217;t create an actual copy of the file on disk &#8211; instead, it creates a &#8220;link&#8221; or pointer to the file data on the disk.  Basically a &#8220;snapshot&#8221; of that directory in-time.   The net result is that you can have 10 &#8220;copies&#8217; of a 10G file that only take up a total of 10G. </p>
<p>This nifty behavior makes cp -al, when combined with rsync,  ideal for backup systems.  One can use the cp -al command to take a &#8220;snapshot&#8221; of a given directory tree at a given time, at the expense of very little additional disk space.  I use this script in concert with my <a href="http://www.eddieoneverything.com/linux/using-rsync-ssh-to-backup-files-between-linux-machines-perl.php">rsync_backup.pl</a> script to keep 21 days of &#8220;snapshot&#8221; backups of each of my machines.</p>
<pre name="code" class="perl">

#!/usr/bin/perl
use POSIX;

# Rotates backup directories w/ cp -al (hardlinks)
# Deletes directories older than $KEEP_DAYS
# Runs each night ahead of backup process
# (c) 2009 eddie@eddieoneverything.com

$KEEP_DAYS=21;
$LOGFILE = "/var/log/rotate_backups";

@BACKUP_DIRS=(
   '/mnt/backup/hansel',
   '/mnt/backup/tiger',
   '/mnt/backup/june'
);

$ts = get_timestamp();

open hLOG, ">>$LOGFILE";
print hLOG "=" x 80, "\n";
print hLOG "Run START at " . `date` . "\n";
print hLOG "=" x 80, "\n";

## Do the rotation
print hLOG "Do today's rotation\n";
foreach $dir ( @BACKUP_DIRS ){
   print hLOG "\t" , `date`;
   $newfn = $dir ."_" .  $ts;
   $cmd = "cp -al $dir $newfn";
   print hLOG "Execute Command: $cmd\n";
   `$cmd`;
}

## Delete old directories
print hLOG "Delete Old Directories\n";
foreach $dir ( @BACKUP_DIRS ){
   $dir=~m/^(.+)\/(.+?)$/;
   $base= $1;
   $stub=$2;
   #print "dir is $dir\nBASE: $base\nSTUB:$stub\n";

   opendir hDIR, "$base" or die "can't open directory $base";
   @dirlist=grep { /^$stub\_/ &#038;&#038; !/^$stub$/  } readdir(hDIR);
   closedir hDIR;

   foreach $d (@dirlist){
      print hLOG "\t" , `date`;
      $d=~/$stub\_([0-9]+)_([0-9]+)_([0-9]+)_.+$/;
      $year= $1;
      $month = $2;
      $day = $3;

      if (dirIsOlder($year, $month, $day)){
         #print "$d\n";
         $remove_dir= $base . '/' . $d;
         $cmd = "rm -Rf \"$remove_dir\"";
         print hLOG "Execute command: $cmd\n";
         `$cmd`;
      }else{
         print hLOG "Keep $d\n";
      }
   }
}
print hLOG "=" x 80, "\n";
print hLOG "Run END at " . `date` . "\n";
print hLOG "=" x 80, "\n";
close hLOG;

# ------------- Subroutines &#038; functions -----------------

sub get_timestamp {
   ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
   $mon+=1;

   if ($mon < 10) { $mon = "0$mon"; }
   if ($mday < 10) { $mday = "0$mday"; }
   if ($hour < 10) { $hour = "0$hour"; }
   if ($min < 10) { $min = "0$min"; }
   if ($sec < 10) { $sec = "0$sec"; }
   $year=$year+1900;

   return $year . '_' . $mon . '_' . $mday . '__' . $hour . '_' . $min . '_' . $sec;
}

sub dirIsOlder{
   ($fyear, $fmonth, $fday) = @_;
   #print "Check $year - $month - $day \n";

   $now  = mktime(localtime());
   $then =  mktime (0, 0 , 0, $fday-1, $fmonth-1, $fyear-1900 , 0, 0);

   $diff_sec = $now - $then;
   $days_since = $diff_sec / 24 / 60 / 60;
   #print "n: $now. t: $then. Diff ($diff_sec) = $days_since\n";
   #print "$days_since $fyear-$fmonth-$fday\n";

   ## Subtract days from today

   if ($days_since > $KEEP_DAYS){
      return 1;
   }else{
      return 0;
   }
}
</pre>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/linux/using-rsync-ssh-to-backup-files-between-linux-machines-perl.php" title="Using rsync &#038; ssh to Backup Files Between Linux Machines (Perl)">Using rsync &#038; ssh to Backup Files Between Linux Machines (Perl)</a></li><li><a href="http://www.eddieoneverything.com/linux/argument-list-too-long-from-rm-command-a-perl-script-to-get-around-the-problem.php" title="&#8220;Argument list too long&#8221; from rm command.   A Perl Script to Get Around the Problem">&#8220;Argument list too long&#8221; from rm command.   A Perl Script to Get Around the Problem</a></li><li><a href="http://www.eddieoneverything.com/articles/managing-server-load-when-unzipping-many-large-files.php" title="Managing Server Load when unzipping many large files">Managing Server Load when unzipping many large files</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-scan-a-computer-for-open-ports.php" title="How to Scan a Computer for Open Ports">How to Scan a Computer for Open Ports</a></li><li><a href="http://www.eddieoneverything.com/articles/the-zen-of-taco-bell-programming-using-unix-tools-to-prevent-reinventing-the-wheel.php" title="The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel">The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel</a></li><li><a href="http://www.eddieoneverything.com/articles/linux-forward-file-not-working-make-sure-you-have-the-permissions-set-correctly.php" title="Linux .forward file not working?  Make sure you have the permissions set correctly">Linux .forward file not working?  Make sure you have the permissions set correctly</a></li><li><a href="http://www.eddieoneverything.com/linux/caution-filename-not-matched-error-when-unzipping-multiple-files-workaround.php" title="Caution: filename not matched error when unzipping multiple files workaround">Caution: filename not matched error when unzipping multiple files workaround</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/linux/rotating-backup-directories-using-cp-al-hardlinks-to-save-disk-space.php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using rsync &amp; ssh to Backup Files Between Linux Machines (Perl)</title>
		<link>http://www.eddieoneverything.com/linux/using-rsync-ssh-to-backup-files-between-linux-machines-perl.php</link>
		<comments>http://www.eddieoneverything.com/linux/using-rsync-ssh-to-backup-files-between-linux-machines-perl.php#comments</comments>
		<pubDate>Sun, 15 Nov 2009 19:27:32 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[system administration]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/?p=342</guid>
		<description><![CDATA[This script performs a network backup using unix&#8217;s rsync command over ssh.  It performs an incremental backup, which means that it only updates new files and files that have changed since the last backup, thus minimizing network traffic.  
This script runs on the source machine (SOURCE) and connects to the backup machine (BACKUP). [...]]]></description>
			<content:encoded><![CDATA[<p>This script performs a network backup using unix&#8217;s rsync command over ssh.  It performs an incremental backup, which means that it only updates new files and files that have changed since the last backup, thus minimizing network traffic.  </p>
<p>This script runs on the source machine (SOURCE) and connects to the backup machine (BACKUP).  (SOURCE->BACKUP). It assumes a user named backup-SOURCE on the backup machine and connects as that user. </p>
<p>One advantage of using SOURCE->BACKUP setup rather than a BACKUP->SOURCE method is that if your BACKUP server is compromised, the attacker will not be able to gain access to all of your production machines.</p>
<p>There are admittedly disadvantages to running a SOURCE->BACKUP setup, rather than a BACKUP->SOURCE setup.  One, you&#8217;ll need a copy of the script on each of the machines that you want to backup, making maintenance a bit more involved.  Second, if your SOURCE machine becomes compromised, the attacker will be able to gain access to your backup server. This second issue can be mitigated by setting the permissions properly on the BACKUP machine.  (This is why I use a separate user account for each machine that I backup.)</p>
<p>How to use this script:</p>
<ol>
<li>Edit the configuration options in the script.</li>
<li>Add a user called &#8220;backup-{$SOURCE} to the BACKUP machine.</li>
<li>Set up the appropriate SSH keys for the user to bypass password prompts.</li>
<li>Set up a cron job to run the script nightly.</li>
<li>If you want Apple-ish &#8220;time machine style&#8221; backups, set up a script to rotate the backups on the BACKUP machine.  I use this <a href="http://www.eddieoneverything.com/linux/rotating-backup-directories-using-cp-al-hardlinks-to-save-disk-space.php">rotate_backups.pl</a> script to make backups using cp -al (hardlinks).</li>
</ol>
<pre name="code" class="pl">

#!/usr/bin/perl
# Filename: rsync_backup.pl
# Will back things up from one computer to another over SSH using rsync.
# Use in conjunction with a rotate script on the destination machine for
# time-machine-like incremental backups.
# Note: SSH SSL auth keys must be installed on each end to avoid passwd prompt
# Assumes a user named "backup-$THIS_COMPUTER" on remote machine.
# All output will go to Logfile
#
# (c) 2009 eddie@eddieoneverything.com 

use Data::Dumper;

# This computer's name.  Used to name the backup files.
$THIS_COMPUTER = "yoakam";

# The remote machine's URL or IP address.
$REMOTE_MACHINE = "127.0.0.1";

# The backup directory on the remote machine
$REMOTE_BACKUP_LOCATION="/mnt/backup";

# Log things
$LOGFILE = "/var/log/rsync_backup";

# Directories to backup.
@BACKUP_DIRS=(
   '/home',
   '/root',
   '/etc',
   '/var/log',
   '/var/lib/mysql',
   '/var/spool/cron'
);

# Directories to ignore.
@IGNORE_DIRS=(
   '/home/lost+found',
   '/home/tmp',
   '/home/virtfs'
);

#####################################################
########### END Configuration options ###############
#####################################################

open hLOG, "&gt;&gt;$LOGFILE";
$now = `date`;
print hLOG "-" x 80, "\n";
print hLOG "START BACKUP $THIS_COMPUTER at $now\n" ;
print hLOG "-" x 80, "\n";
# Get a list of dirs to back up
foreach (@BACKUP_DIRS){
   $dir = $_;
   opendir(DIR, $dir) || alert ("cant opendir $dir: $!");
   while ($file = readdir(DIR)){
      if ($file ne '.' &amp;&amp; $file ne '..'){
         $my_file = $dir . "/" .  $file;
         if ( -d $my_file){
            if (grep {/$my_file/} @IGNORE_DIRS){
               print hLOG "Ignore Dir: $my_file\n";
            }else{
               print hLOG "Dir: $my_file\n";
               push @BACKUP_LIST, {'dir' =&gt; $dir, 'name'=&gt;$file};
            }
         }else{
            print hLOG "file is $my_file -- \n";
            @arr_temp =  ($dir, $my_file);
            push @BACKUP_LIST, {'dir' =&gt; $dir, 'name'=&gt;$file};
         }
      }
   }
   closedir DIR;
}

#print Dumper(@BACKUP_LIST);

#Back up each dir in the backup list
foreach $my_entry (@BACKUP_LIST){
   $dir = $my_entry-&gt;{'dir'};
   $b = $my_entry-&gt;{'name'};

   $cmd = "rsync -avz --delete-after -e ssh \"$dir/$b\" backup-$THIS_COMPUTER\@$REMOTE_MACHINE:\"/$REMOTE_BACKUP_LOCATION/$THIS_COMPUTER$dir\"";
   $now=`date`;
   print hLOG "\n$now\t$cmd ";
   #print "$cmd\n";
   `$cmd &gt;&gt; $LOGFILE 2&gt;&amp;1`;
}

$now = `date`;
print hLOG "-" x 80, "\n";
print hLOG "END BACKUP of $THIS_COMPUTER at $now\n" ;
print hLOG "-" x 80, "\n";
close hLOG;

###################### Subs #########################
sub alert(){
   $a=shift(@_);
   print hLOG "#############################\n";
   print hLOG "#############################\n";
   print hLOG "#############################\n";
   print hLOG "Cannot backup $a $!\n";
   print hLOG "#############################\n";
   print hLOG "#############################\n";
   print hLOG "#############################\n";
}</pre>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/linux/rotating-backup-directories-using-cp-al-hardlinks-to-save-disk-space.php" title="Rotating Backup Directories using cp -al (hardlinks) to Save Disk Space">Rotating Backup Directories using cp -al (hardlinks) to Save Disk Space</a></li><li><a href="http://www.eddieoneverything.com/articles/managing-server-load-when-unzipping-many-large-files.php" title="Managing Server Load when unzipping many large files">Managing Server Load when unzipping many large files</a></li><li><a href="http://www.eddieoneverything.com/linux/argument-list-too-long-from-rm-command-a-perl-script-to-get-around-the-problem.php" title="&#8220;Argument list too long&#8221; from rm command.   A Perl Script to Get Around the Problem">&#8220;Argument list too long&#8221; from rm command.   A Perl Script to Get Around the Problem</a></li><li><a href="http://www.eddieoneverything.com/articles/how-to-scan-a-computer-for-open-ports.php" title="How to Scan a Computer for Open Ports">How to Scan a Computer for Open Ports</a></li><li><a href="http://www.eddieoneverything.com/articles/the-zen-of-taco-bell-programming-using-unix-tools-to-prevent-reinventing-the-wheel.php" title="The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel">The Zen of Taco Bell Programming &#8211; Using Unix Tools to Prevent Reinventing the Wheel</a></li><li><a href="http://www.eddieoneverything.com/programming/how-to-easily-install-a-perl-module-in-ubuntu-linux.php" title="How to Easily Install a Perl Module In Ubuntu Linux">How to Easily Install a Perl Module In Ubuntu Linux</a></li><li><a href="http://www.eddieoneverything.com/articles/linux-forward-file-not-working-make-sure-you-have-the-permissions-set-correctly.php" title="Linux .forward file not working?  Make sure you have the permissions set correctly">Linux .forward file not working?  Make sure you have the permissions set correctly</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/linux/using-rsync-ssh-to-backup-files-between-linux-machines-perl.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to do a search and replace in multiple files using Perl</title>
		<link>http://www.eddieoneverything.com/linux/how-to-do-a-search-and-replace-in-multiple-files-using-perl.php</link>
		<comments>http://www.eddieoneverything.com/linux/how-to-do-a-search-and-replace-in-multiple-files-using-perl.php#comments</comments>
		<pubDate>Wed, 21 Jan 2009 22:48:38 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/linux/how-to-do-a-search-and-replace-in-multiple-files-using-perl.php</guid>
		<description><![CDATA[Over the years, I&#8217;ve written a number of &#8220;search and replace in multiple files&#8221; scripts.   Working on a computer that didn&#8217;t have my standard, custom toolset available, I found myself searching for an alternative.
Found this tip over at Dzone Snippets &#8211; do it all with a single line of perl.
perl -pi -w -e [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#468banner--></p>
<p>Over the years, I&#8217;ve written a number of &#8220;search and replace in multiple files&#8221; scripts.   Working on a computer that didn&#8217;t have my standard, custom toolset available, I found myself searching for an alternative.</p>
<p>Found this tip over at <a href="http://snippets.dzone.com/posts/show/506">Dzone</a> Snippets &#8211; do it all with a single line of perl.</p>
<blockquote><p>perl -pi -w -e &#8217;s/search/replace/g;&#8217; *.txt</p></blockquote>
<p>Of course, you&#8217;ll need Perl installed on your system and command line access to make use of it.</p>
<p><!--adsense#largerectanglenowrap--></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/programming/how-to-use-global-variables-from-another-file-in-a-perl-module-or-package.php" title="How To Use Global Variables From Another File In A Perl Module or Package">How To Use Global Variables From Another File In A Perl Module or Package</a></li><li><a href="http://www.eddieoneverything.com/shaving/lord-platinum-de-razor-blade-review.php" title="Lord Platinum DE Razor Blade Review">Lord Platinum DE Razor Blade Review</a></li><li><a href="http://www.eddieoneverything.com/articles/trig-razor-blade-review.php" title="Trig Razor Blade Review">Trig Razor Blade Review</a></li><li><a href="http://www.eddieoneverything.com/deals/finally-a-gas-coupon-worth-clipping-from-exxon.php" title="Finally &#8211; A Gas Coupon Worth Clipping, from Exxon">Finally &#8211; A Gas Coupon Worth Clipping, from Exxon</a></li><li><a href="http://www.eddieoneverything.com/music/lyrics-to-living-in-the-promiseland-by-willie-nelson.php" title="Lyrics to &#8220;Living in the Promiseland&#8221; by Willie Nelson">Lyrics to &#8220;Living in the Promiseland&#8221; by Willie Nelson</a></li><li><a href="http://www.eddieoneverything.com/windows-xp/how-to-take-a-screenshot-in-windows-xp.php" title="How to take a screenshot in Windows XP">How to take a screenshot in Windows XP</a></li><li><a href="http://www.eddieoneverything.com/business-tips/dell-support-or-lack-thereof.php" title="Dell Support, or lack thereof">Dell Support, or lack thereof</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/linux/how-to-do-a-search-and-replace-in-multiple-files-using-perl.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically renaming files downloaded with Coast to Coast AM Media Center</title>
		<link>http://www.eddieoneverything.com/perl/automatically-renaming-files-downloaded-with-coast-to-coast-am-media-center.php</link>
		<comments>http://www.eddieoneverything.com/perl/automatically-renaming-files-downloaded-with-coast-to-coast-am-media-center.php#comments</comments>
		<pubDate>Tue, 08 Apr 2008 02:07:01 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[productivity]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/perl/automatically-renaming-files-downloaded-with-coast-to-coast-am-media-center.php</guid>
		<description><![CDATA[I&#8217;m an insomniac. 
I have trouble falling asleep at night because thoughts never seem to stop racing through my head &#8211; Did I do X yet?  What if I did Y?  Ooh, I could make it easier to do Y &#8230;  Hey, I have a cool idea for an awesome invention&#8230;  [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense-->I&#8217;m an insomniac. </p>
<p>I have trouble falling asleep at night because thoughts never seem to stop racing through my head &#8211; <em>Did I do X yet?  What if I did Y?  Ooh, I could make it easier to do Y &#8230;  Hey, I have a cool idea for an awesome invention&#8230;  and I&#8217;m starting to get excited about it &#8230; (!)</em></p>
<p>Listening to radio shows helps me quiet my mind &#038; get to sleep.  To that end, I use the <a href="http://download.premiereradio.net/maven/clients/Coast_to_Coast_AM_Media_Center.exe">Coast to Coast AM Media Center</a> to automatically download shows from the Coast to Coast AM website. (Sure, the content can be really nutty from time to time, but I treat it as entertainment &#038; fiction, not a show to be taken seriously.)  One of the limitations of the downloader is that the downloaded mp3s don&#8217;t have very useful names &#8211; instead of being named something useful, like &#8220;03-20  John Titor and Time Travel,&#8221; the files instead carry largely useless names such as &#8220;Coast to Coast &#8211; Mar 20 2008 &#8211; Hour 2.mp3.&#8221;</p>
<p>I wrote the below perl script to make the downloaded file names more useful.  It connects to the Coast to Coast AM website, looks up the file name, creates a directory with that filename, then moves the downloaded mp3s to that directory.  To run the script on your Windows machine, you&#8217;ll need to have the <a href="http://www.cygwin.com/">Cygwin</a> suite installed, along with the cygwin perl module.</p>
<pre>#!/usr/bin/perl

$DIR="/cygdrive/c/Documents and Settings/eddie/My Documents/coast to coast am media center";

opendir (DIR, $DIR) or die "cant open dir $DIR";
while (my $file = readdir (DIR)){
   if ($file=~/mp3$/){
      #process mp3 file
      #print "$file \n";
      $file=~/(\w+) ([0-9]+) ([0-9]+)/;
      #$file=~/^.+? (\w) ([0-9]+) ([0-9]+) .+$/;
      #print "mon $1 \n day $2 \n year $3\n";
      $y=$3;
      $month=$1;
      $d=$2;

      print "month is $month\n";
      if ($month eq  "Feb"){
         $m="02";
      }elsif($month eq "Mar"){
         $m="03";
      }elsif($month eq "Apr"){
         $m="04";
      }elsif($month eq "May"){
         $m="05";
      }elsif($month eq "Jun"){
         $m="06";
      }elsif($month eq "Jul"){
         $m="07";
      }elsif($month eq "Aug"){
         $m="08";
      }elsif($month eq "Sep"){
         $m="09";
      }elsif($month eq "Oct"){
         $m="10";
      }elsif($month eq "Nov"){
         $m="11";
      }elsif($month eq "Dec"){
         $m="12";
      }elsif($month eq "Jan"){
         $m="01";
      }else{
         $m="XX";
      }

      $date_string = $m . "-" . $d;

      if ($SHOWS[$y-$m-$d]){
         $title=$SHOWS[$y-$m-$d];
      }else{
         $url = "http://www.coasttocoastam.com/shows/$y/$m/$d.html";
         #print "getting URL $url...\n";
         #&lt;h2&gt;&lt;a name="recap"&gt;&lt;/a&gt;Title&lt;/h2&gt;
         system("wget -q -O /tmp/temp.$$ $url");
         $file_contents = `cat /tmp/temp.$$`;
         $file_contents=~/&lt;h2&gt;&lt;a name\s*=\s*"recap"&gt;&lt;\/a&gt;(.+?)&lt;\/h2&gt;/;
         $title = $1;
         $title=~s/\&#038;/and/gis;
         $title=~s/\:/-/gis;
         $title=~s/\!//gis;
         $desc=~s/&lt;.+?&gt;//gis;
         print "TITLE:  $title\n";
         $SHOWS[$y-$m-$d] = $title;
         system("rm  /tmp/temp.$$");
      }

      ## move the file to the proper directory
      $dirname = $date_string . " " . $title;
      if (-e "$DIR/$dirname"){
         #dir already exists
      }else{
         $cmd="mkdir  \"$DIR/$dirname\"";
         system ($cmd);
      }

      $cmd = "mv \"$DIR/$file\" \"$DIR/$dirname\"";
      #print "want to $cmd\n";
      system ($cmd);

   }
}
close DIR;</pre>
<p><!--adsense#largerectanglenowrap--></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/articles/for-a-cheap-cell-phone-plan-check-out-virgin-mobil-usa.php" title="For a cheap cell phone plan, check out Virgin Mobile USA">For a cheap cell phone plan, check out Virgin Mobile USA</a></li><li><a href="http://www.eddieoneverything.com/consumer-protection/fraudulent-calls-from-904-398-4657.php" title="Fraudulent calls from 904-398-4657">Fraudulent calls from 904-398-4657</a></li><li><a href="http://www.eddieoneverything.com/finance/what-does-it-mean-to-be-upside-down-on-a-loan.php" title="What does it mean to be &#8220;upside down&#8221; on a loan?">What does it mean to be &#8220;upside down&#8221; on a loan?</a></li><li><a href="http://www.eddieoneverything.com/lists/list-of-the-largest-us-universities-by-enrollment-2005.php" title="List of the Largest U.S. Universities by Enrollment &#8211; 2005">List of the Largest U.S. Universities by Enrollment &#8211; 2005</a></li><li><a href="http://www.eddieoneverything.com/deals/get-free-shipping-at-staplescom.php" title="Get Free Shipping at Staples.com">Get Free Shipping at Staples.com</a></li><li><a href="http://www.eddieoneverything.com/sports/list-of-triple-crown-winners.php" title="List of  Triple Crown Winners">List of  Triple Crown Winners</a></li><li><a href="http://www.eddieoneverything.com/articles/changing-the-margin-size-on-the-kindle.php" title="Changing the Margin Size on the Kindle">Changing the Margin Size on the Kindle</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/perl/automatically-renaming-files-downloaded-with-coast-to-coast-am-media-center.php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to do a search and replace in multiple files using perl and linux</title>
		<link>http://www.eddieoneverything.com/linux/how-to-do-a-search-and-replace-in-multiple-files-using-perl-and-linux.php</link>
		<comments>http://www.eddieoneverything.com/linux/how-to-do-a-search-and-replace-in-multiple-files-using-perl-and-linux.php#comments</comments>
		<pubDate>Tue, 26 Feb 2008 16:36:04 +0000</pubDate>
		<dc:creator>eddie</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.eddieoneverything.com/linux/how-to-do-a-search-and-replace-in-multiple-files-using-perl-and-linux.php</guid>
		<description><![CDATA[So you&#8217;ve got 100 files in a directory and you want to replace the string &#8220;foo&#8221; with &#8220;bar&#8221;.  Stop before you waste your time opening up every single file and making the change, you can make all of the changes with a single line of perl.
perl -pi -w -e 's/foo/bar/g' *\.php 
On his blog, [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsense#468banner--><br />
So you&#8217;ve got 100 files in a directory and you want to replace the string &#8220;foo&#8221; with &#8220;bar&#8221;.  Stop before you waste your time opening up every single file and making the change, you can make all of the changes with a single line of perl.</p>
<p><code>perl -pi -w -e 's/foo/bar/g' *\.php </code></p>
<p>On his blog, <a href="http://www.liamdelahunty.com/tips/linux_search_and_replace_multiple_files.php">Liam Delahunty</a> explains what each of the following command line switches means.</p>
<p><code><br />
    -e means execute the following line of code.<br />
    -i means edit in-place<br />
    -w write warnings<br />
    -p loop<br />
</code></p>
<p>There you have it &#8211; a nice and easy Perl solution that should save you tons of time.</p>
<p><!--adsense#largerectanglenowrap--></p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.eddieoneverything.com/legal/judge-orders-lawyers-to-play-game-of-rock-paper-scissors-to-resolve-dispute.php" title="Judge Orders Lawyers to Play Game of &#8220;Rock Paper Scissors&#8221; to Resolve Dispute">Judge Orders Lawyers to Play Game of &#8220;Rock Paper Scissors&#8221; to Resolve Dispute</a></li><li><a href="http://www.eddieoneverything.com/grammar/throw-your-reader-a-rope-stephen-king-on-the-passive-voice.php" title="Throw Your Reader a Rope: Stephen King on the Passive Voice">Throw Your Reader a Rope: Stephen King on the Passive Voice</a></li><li><a href="http://www.eddieoneverything.com/articles/validating-an-email-address-with-phps-filter_var-isnt-perfect.php" title="Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect">Validating an Email Address with PHP&rsquo;s filter_var isn&rsquo;t perfect</a></li><li><a href="http://www.eddieoneverything.com/shaving/dont-use-canned-shaving-cream-with-a-safety-razor.php" title="Don&rsquo;t use Canned Shaving Cream with a Safety Razor">Don&rsquo;t use Canned Shaving Cream with a Safety Razor</a></li><li><a href="http://www.eddieoneverything.com/articles/how-the-red-cross-lost-me-as-a-donor-again.php" title="How the Red Cross Lost Me As A Donor &#8211; Again">How the Red Cross Lost Me As A Donor &#8211; Again</a></li><li><a href="http://www.eddieoneverything.com/calculators/subway-sandwich-calorie-carb-nutrition-calculator.php" title="Subway Sandwich Calorie &#038; Carb Nutrition Calculator">Subway Sandwich Calorie &#038; Carb Nutrition Calculator</a></li><li><a href="http://www.eddieoneverything.com/articles/how-can-i-deposit-a-check-for-someone-else.php" title="How can I deposit a check for someone else?">How can I deposit a check for someone else?</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.eddieoneverything.com/linux/how-to-do-a-search-and-replace-in-multiple-files-using-perl-and-linux.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

