Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> $ sqlite3 whois-log-copy.db "select source from queries"|sort|uniq|wc -l

Oh cool they saved the logs in a database ! Wait... |sort|uniq|wc -l ?? But why ?



SELECT COUNT( DISTINCT source ) FROM queries ORDER BY source ASC

-- COUNT ( DISTINCT ... ) ~= uniq | wc -l ;; sort without -u is this busybox? ORDER BY col ASC

-- wait this doesn't need sort and uniq if it's just being counted...

SELECT COUNT( DISTINCT source ) FROM queries


bash nerds vs sql nerds I guess, these people are bash nerds


beats up re-re-remembering how to do it in sql


And probably because for quick things like that you’re already working in a “pipeline”, where you first want to see some of the results so you output with SQLite, and then add more to the pipeline. Similarly, I often do ‘cat file | grep abc’ instead of just grep, might be probably out of habit.


I found that this is actually a good use case for LLMs. You can probably paste that one liner up there and ask it to create the corresponding SQL query.


yeah, they're good for cursed tools like that, ffmpeg, excel macros, etc etc


yeah, they could have done `sqlite …|sort -u|wc -l` instead and saved themselves a process invocation!


Hey now if you're just gonna count lines no need to sort it at all.


you need to sort it in order to uniq it, because uniq only removes duplicate consecutive lines.


You know, it's been so long since I've used it, I completely forgot that fact. Alright, you win the battle of best correct bad sql to bash pipeline :).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: