>new.dat perl -e'print "newline 111\nnewline 222\n";'
>test.dat perl -e'
my $s = "dla4\n.Ends\nshe\n.Ends\nres\n.Ends\n";
my $n = 2**30 / length( $s );
print $s for 1 .. $n;
'
$ \cp test.dat test_copy.dat && time perl zdim.pl test_copy.dat
real 0m0.530s
user 0m0.000s
sys 0m0.014s
$ \cp test.dat test_copy.dat && time perl zdim.pl test_copy.dat
real 0m0.528s
user 0m0.014s
sys 0m0.000s
$ \cp test.dat test_copy.dat && time perl zdim.pl test_copy.dat
real 0m0.505s
user 0m0.014s
sys 0m0.000s
$ \cp test.dat test_copy.dat && time perl tlp.pl test_copy.dat new.dat
real 2m41.277s
user 2m39.820s
sys 0m1.450s
$ \cp test.dat test_copy.dat && time perl tlp.pl test_copy.dat new.dat
real 2m38.551s
user 2m37.009s
sys 0m1.540s
Note: Uses ~6 GiB of memory for a 1 GiB file.
$ time sh -c 'tac test.dat | awk -v new_dat="new.dat" '\''1;/\.Ends/ && !(seen++) {system("tac " new_dat)}'\'' | tac >test_copy.dat'
real 0m27.060s
user 0m25.874s
sys 0m6.544s
$ time sh -c 'tac test.dat | awk -v new_dat="new.dat" '\''1;/\.Ends/ && !(seen++) {system("tac " new_dat)}'\'' | tac >test_copy.dat'
real 0m28.995s
user 0m25.365s
sys 0m6.195s
$ time awk -v new_dat="new.dat" 'FNR==NR { if ($0 ~ /\.Ends/) lastline=FNR; next} FNR==lastline { system("cat "new_dat)
}; 1' test.dat test.dat >test_copy.dat
real 0m53.121s
user 0m52.400s
sys 0m0.700s
$ time awk -v new_dat="new.dat" 'FNR==NR { if ($0 ~ /\.Ends/) lastline=FNR; next} FNR==lastline { system("cat "new_dat) }; 1' test.dat test.dat >test_copy.dat
real 0m53.079s
user 0m52.285s
sys 0m0.770s