The dd approach is interesting. Editing a file like that in place cowboy style with dd would fill me with anxiety however
Something like
readLineOffset = 301
writeLineOffset = 1
While not read eof
line = Read(readLineOffset)
Write(WriteLineOffset, line)
readLineOffset ++
writeLineOffset ++ #!/usr/bin/perl
open(my $fh,">foo") or die($!);
for (1..100) {print $fh "$_\n"};
close($fh);
open($fh,'+<','foo') or die($!);
while(<$fh>) {
my $spot=tell($fh)-length($_);
seek($fh,$spot,SEEK_SET) or die($!);
s/\d/X/g;#replace digits with X's
print $fh "$_" or die($!);
}
close($fh);
If his file has lines of equal size, this would be fairly easy to do in place. Would be a little more complicated if not.That people normally use temporary files, has two reasons: The first is that it is much safer if something goes wrong. You then still have the original and not some half-way processed file. The other reason is that reading and writing in text mode does not really work. But you can of course process text files as binary files and deal with line endings yourself.