Okay. Here is the code I came up with attempting to implement your suggestion and anon's. I will adopt for the real deal shortly and post soon.
HEADER a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 END HEADER b1 b2 c1 c2 .. z1 z2
I chose a5 as the line to change and want to only change that line, everything should be exactly the same.
#!/usr/bin/env perl use strict; use warnings; use Data::Dump; open (my $fh, 'message.txt') or die $!; LINE: while (<$fh>) { last LINE if /END HEADER\s\w/s; } my $headerEndingPositionInBytes = tell($fh); print "Found header ending at $headerEndingPositionInBytes\n"; sysseek $fh,0,0; # Rewind to beginning of file my $header; my $bytesRead = sysread $fh, $header, $headerEndingPositionInBytes; print "Read $bytesRead into header variable\n"; my @lines = split '\n', $header; for (0..$#lines) { $lines[$_] =~ s/^a5$/new magic/; } $header = join "\n",@lines; open (my $newFile, '>','message-fixed.txt') or die "$!"; syswrite($newFile, $header); # Write the header my $blockSize = 32 * 1<<10; #32k my $window; while (my $bytesRead = sysread $fh, $window,$blockSize) { syswrite $newFile, $window, $blockSize; } syswrite $newFile, "\n";

In reply to Re^4: In place editing without reading further by trippledubs
in thread In place editing without reading further by trippledubs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.