News for hackers. Stuff that matters.
Re:Unix tricks by niggler on Thursday March 07, 2013 @10:19AM (#5338051)
The sort | uniq method literally needs to sort the file and pipe it to uniq, a far more memory-intensive operation than the single-pass awk check. You can write your own hash function in AWK if you think you may overstep memory, but of course you risk hash collisions. It's a tradeoff.

I tried it on a 1U server with 24GB ram a few years ago and found that the sort was thrashing at the 10GB file size while AWK handled it easily

Re:Unix tricks by stevvooe on Thursday March 07, 2013 @11:03AM (#5338324)
Sort will actually externally sort blocks into temp files and merge them. Adjusting this block size can help with thrashing.

Awk may still be better for uniquification.

Re:Unix tricks by enigmo on Thursday March 07, 2013 @11:42AM (#5338561)
What about 'sort -u' ?
Re:Unix tricks by stevvooe on Thursday March 07, 2013 @01:30PM (#5339237)
I'm not sure. I haven't closely studied the difference between each algorithm. My guess would be that sort -u would perform better as the data set gets larger with a good block size setting because it does do an external sort. Cardinality would also affect the performance. If the unique set handily fits in memory, an external sort on a large data set wouldn't be very efficient.
Re:Unix tricks by gav on Thursday March 07, 2013 @11:45AM (#5338581)
Or you can use `sort -u` and not have to pipe to `uniq`.
Re:Unix tricks by carlesfe on Thursday March 07, 2013 @10:23AM (#5338079)
Yes, awk does some real black bagic. It's awesome how it can parse really, really big files.