in reply to Re^2: file phrase substitutation
in thread file phrase substitutation
Here's a solution that does it all in perl:
#!/usr/bin/perl use warnings; use strict; use File::Find; use Tie::File; find (\&replace,"/path/to/directory"); sub replace { my $cur_file=$File::Find::name; return if (!-f $cur_file || !-w $cur_file); tie my @file_content,'Tie::File',$cur_file or die "Couldn't tie file $cur_file"; for (@file_content) { s/this phrase/that locution/g; } }
You may want to read the Tie::File perldoc regarding file locking and memory consumption.
And just for completeness, here's a solution that does it all without perl:
find this/ -type f -exec sed -i 's/gg/dd/g' {} \;
|
|---|