First, the one-liner itself (shown with arbitrary example arguments and -t switch set), followed by the script file p-in-p.p (I follow a naming convention of making Perl application -- executable -- scripts with names *.p, library code in files named *.pl).
Also, please save the file
p-in-p.p (or whatever you want to
name it) to a reasonable location on your
HD and then edit the one-liner below so the
system can find it there (fully qualified path
specification).
perl -"MFile::Dosglob" -e "sub NX{return shift @ARGV;};$P=quotemeta NX;$S=NX;$gb=NX; $opt_t=($t=NX)?$t:undef; push @ARGV,glob(qq{*.$gb}); @O=@Y=@ARGV; for(@O){ $T{$_}=(stat $_)[9]; print qq{\n},$_,q' ',($lt=localtime($T{$_})),qq{\n} ;} if (! $opt_d){for (@O){splice @O,$n++,1,q{\"}. $_ .q{\"};} open(TF,qq{>TMP.~});print TF join qq{\n},@O,$S,$P;close (TF); ($ev=scalar eval qx{TYPE e:\\scr\\p-in-p.p}) or warn $@; if ($opt_t){ for(@Y){ print STDERR qq{\n$_ ! };$r+=utime(time,$T{$_},$_); }; print qq{\n\n Filetimes restored for $r files out of $ev files.\n\n};}}" "i" "I" "txt" -t
#!perl #p-in-p.p open LOG, ">LOG.~" or die $!; @ARGV = split /\n/,`TYPE .\\TMP.~`; print LOG "Patterns: ",qq{\n} x 2, join qq{\n}, @ARGV[$#ARGV,$#ARGV-1] +,qq{\n}; $P=pop @ARGV; $S=pop @ARGV; @ARGV = sort {uc($a) cmp uc($b)} @ARGV; print LOG "\n" . @ARGV . " Files: ",qq{\n} x 2, join qq{\n},@ARGV, qq{ +\n}; @ARGV = &Dequote(@ARGV); my $countfiles = $#ARGV + 1; $^I=q{.PBU}; $S =~ s#\\@#@#g; while (<>){ my $former = $_; chomp $former; if (s/($P)/$S/g){ print LOG qq{\n},q{ Now in file: }, $ARGV , qq{:\n}; print LOG qq{Replacing: *${1}* in: } .'"' . $former . '"' .qq{ +\n}. qq{with: } .'"'. $_ .'"'. qq{\n}; print; } print; }; close (LOG); system "notepad LOG.~"; sleep 3; unlink qw{LOG.~ TMP.~}; return $countfiles; sub Dequote { for (@_) { $_ = substr ($_,1,(length $_) - 2); } return @_; }
In reply to In-Place editing system by Intrepid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |