my $gpg = '/home/gpghrp/.gnupg'; my $file = "$gpg/scripts/gpg_encr.saved"; my $temp = "$file.new"; open(OLD, '<', $file) or die "Can't open $file: $!\n"; open(NEW, '>', $temp) or die "Can't create $temp: $!\n"; while (<OLD>) { # Faster than regexp for plain text. if (index($_, '(?)readonly tlx=') >= 0) { substr($_, 13, 8, "blah"); } print NEW $_; } close(NEW); close(OLD); rename($temp, $file) or die "Can't update $file: $!\n";
or as a one-liner:
perl -i -pe '/\Q(?)readonly tlx=\E/ && substr($_,13,8,"blah");' /home/ +gpghrp/.gnupg/scripts/gpg_encr.saved
In reply to Re: search and replace with a temp file at a certain substr position
by ikegami
in thread search and replace with a temp file at a certain substr position
by drock
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |