That's a great solution, too. At the test with 960.000 lines, it took about 13 seconds. Almost identical with the first solution from cyborgski, which takes about 12 seconds on my computer. Only the second solution of cyborgski needs about 40 seconds for this amount of data.
At the test with 120.000 lines all 3 solutions are, from the feeling, equally fast.