in reply to Replacing expression on certain line numbers
Another option is to use list for the line numbers. The algorithm scans only once through data file
then you could use it like filter on UNIX-like OS-es:# first read and numericaly sort the lines my @lines = sort {$a <=> $b} <>; # then loop over data on STDIN # and write it to STDOUT my $line = shift @lines; while (<>){ if ($.==$line){ s/foo/bar/g; $line = shift @lines; } print; }
cat data | ./script index-file > result
Best regards
P.S. Code is not tested
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Replacing expression on certain line numbers
by shmem (Chancellor) on Aug 03, 2008 at 22:00 UTC | |
Re^2: Replacing expression on certain line numbers
by FunkyMonk (Chancellor) on Jul 14, 2008 at 15:32 UTC |
In Section
Seekers of Perl Wisdom