[plug] Extreme text editing

Jens Porup jens at cyber.com.au
Wed Oct 8 07:32:14 WST 2003


On Tue, Oct 07, 2003 at 09:52:59PM +0800, J Michael Gilks wrote:
> Today I had an unfortunate experience with a large text file. A guy had 
> concatenated a number of files to form a MEGA velocity file which 
> unfortunately had an error on line 10,557,152.
> The total file was 4.3GB on a remote NFS partition and contained 66,709,648 
> lines. I eventually opened the file with VI navigated to line 10,557,152, 
> changed the fifteen offending characters to spaces and closed the file after 
> saving.
> Unfortunately each operation took about 45 minutes. So 1.5 hours to load, edit 
> and save the file.
> Does anyone have any ideas about how this could be done without loading the 
> entire file.
> I would have simply edited the offending source file and re concatenated the 
> whole lot, but the guy has gone on holiday and we are unsure exactly what he 
> did.
> 
> Thanks in advance.

In Perl:

#!/usr/bin/perl

use strict;
use warnings;

open BIGFILE, "<testfile.txt" or die "couldn't open my big text file!\n";
open NEWFILE, ">outputfile.txt" or die "couldn't open the output file!\n";

while (<BIGFILE>)
{
	#$. is a special Perl variable that contains the line number
    s/FOO/BAR/ if ( $. == 10557152 );

	#print to a second file, just in case
	print NEWFILE;
}

Cheers,

Jens
_______________________________________________
plug mailing list
plug at plug.linux.org.au
http://mail.plug.linux.org.au/cgi-bin/mailman/listinfo/plug


More information about the plug mailing list