[ create a new paste ] login | about

Link: http://codepad.org/oIxzSRfS    [ raw code | fork ]

cbuckley - Perl, pasted on Jan 9:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl
# usage: ./script.pl filename search replacement

$^I = '.orig'; # create backup of file at file.orig

my $search = $ARGV[1];
my $replace = $ARGV[2];
my $difference = length $search - length $replace;

@ARGV = ($ARGV[0]);
while (<>) {
    s~s:([0-9]+):"$search([^"]*)~"s:".($1-$difference).":\"$replace$2"~ge;
    print;
}


Create a new paste based on this one


Comments: