in reply to Need one-liner to s///g in all sub-dirs
rob@budapest:~$ find2perl . -type f -exec perl -pi.bak -e 's/old/new/g +' {} \; #!/usr/bin/perl-5.005 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; require "find.pl"; # Traverse desired filesystems &find('.'); exit; sub wanted { (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -f _ && &exec(0, 'perl','-pi.bak','-e','s/old/new/g','{}'); } sub exec { local($ok, @cmd) = @_; foreach $word (@cmd) { $word =~ s#{}#$name#g; } if ($ok) { local($old) = select(STDOUT); $| = 1; print "@cmd"; select($old); return 0 unless <STDIN> =~ /^y/; } chdir $cwd; # sigh system @cmd; chdir $dir; return !$?; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re(2): Need one-liner to s///g in all sub-dirs
by dvergin (Monsignor) on Aug 25, 2001 at 07:40 UTC | |
by rob_au (Abbot) on Aug 25, 2001 at 08:14 UTC | |
by dvergin (Monsignor) on Aug 25, 2001 at 09:18 UTC | |
by blakem (Monsignor) on Aug 25, 2001 at 09:32 UTC | |
by dvergin (Monsignor) on Aug 25, 2001 at 10:01 UTC | |
| |
by rob_au (Abbot) on Aug 25, 2001 at 09:47 UTC | |
by dvergin (Monsignor) on Aug 25, 2001 at 10:08 UTC | |
by chipmunk (Parson) on Aug 25, 2001 at 16:47 UTC |