|
From: | Ivan |
Subject: | removing blank lines: "grep ." is really slow |
Date: | Thu, 15 Apr 2010 20:04:35 -0400 |
I used to use grep .for removing blank lines, until I realized how slow it is for large numbers of lines. So I switched to
grep -v '^$', which is as fast as one would expect (well, not with the grep that comes with MacOSX 10.5.8 (GNU grep version 2.5.1), but this seems to have been fixed sometime between 2.5.1 and 2.6.3).
Still, it seems like "grep ." should be a lot faster than it is. On my 5-year-old powerbook, it takes about 1 second per thousand lines, when the number of lines is bigger than about ten thousand and most lines are nonblank. (For smaller numbers of lines, the runtime ramps up faster than linear in the number of lines, but it seems to level out to linear. Not a good linear, but linear nonetheless.)
best, Ivan
[Prev in Thread] | Current Thread | [Next in Thread] |