In a message dated Wed, 22 May 2002, Paul Company writes:

>
> I want to replace a string "/usr/local" with another
> string "/tmp/local" in a binary file.
>
> This is what I wrote:
> [...]

This seems like overkill to me.  If you're only doing this as a one-off,
then memory shouldn't be a problem.  So, why not just slurp the whole file
in as a string, and do a string substitution:


#!/usr/bin/perl -w
use strict;
my $in = shift;
my $out = shift;
undef $/;
open INPUT, $in
  or die "Can't open $in: $!\n";
my $text = <INPUT>;
$text =~ s|/usr/local|/tmp/local|g;
open OUT, ">$out"
  or die "Can't open $out: $!\n";
print OUT $text;

(By the way, your problem before?  You were doing a grep -b on the output
of *strings*, not on the file itself, so the block number you got was the
offset into the strings output, not the original file.)

Trey


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to