[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: linecut (further refinement)
From: |
Paul Eggert |
Subject: |
Re: linecut (further refinement) |
Date: |
Wed, 02 Jan 2008 09:30:12 -0800 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
Steven Schubiger <address@hidden> writes:
> linecut performed a bit more than 3-times faster than the script).
Here's an Awk script that ran twice as fast as the script you used,
which suggests that scripting is still pretty competitive with C here,
if you choose a faster implementation. I tested it using Mawk, on a
text file with 15,699,634 bytes and 514,573 lines.
#! /usr/bin/mawk
BEGIN {
sets[1, 1] = 1
sets[1, 2] = 2
sets[2, 1] = 20
sets[2, 2] = 24
sets[3, 1] = 50
sets[3, 2] = 100
sets[4, 1] = -30
sets[4, 2] = -1
}
{ line[NR] = $0 }
END {
for (i=1; i<=4; i++) {
start = sets[i, 1]
end = sets[i, 2]
if (start < 0) start = NR + start
if (end < 0) end = NR + end
for (current = start; current <= end; current++) print line[current]
}
}