in reply to Re: Search & Replace in subdirectory files
in thread Search & Replace in subdirectory files
The following code uses File::Find and Tie::File. Note that Tie::File reads each line into an array so you can attempt a substitution. It also edits the file in place so that the original file will be changed to one with the substitutions. Be *careful* of this code as it will change your original files! Maybe set up a dummy directory with some dummy files to test it. I did to test this script! Note that this will change all files in the top directory, /some/dir_name, and goes through each sub_directory looking at all the files.
Hope this helps#!/usr/bin/perl use strict; use warnings; use Tie::File; use File::Find; my @directories_to_search = ("/some/dir_name"); find(\&wanted, @directories_to_search); sub wanted { if (-f) { tie my @array, 'Tie::File', $_ or die $!; s/\$Log/\$History/gi for @array; } }
Chris
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Search & Replace in subdirectory files
by Anonymous Monk on Apr 23, 2004 at 23:47 UTC | |
|
Re: Re: Re: Search & Replace in subdirectory files
by Rina (Initiate) on Apr 26, 2004 at 16:23 UTC | |
|
Re: Re: Re: Search & Replace in subdirectory files
by Rina (Initiate) on May 18, 2004 at 21:27 UTC |