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

Am I missing something or is the article's central example using `tail` fundamentally broken?

The `sort` blocks until input is closed yet `tail -f` never closes its output.



Not to mention, they're under-using awk. Tailing this seems completely unnecessary.

The original from TFA:

`tail -fq /var/log/nginx/access.log | awk '{print $7}' | sort | uniq -c | sort -rn`

can be replaced with:

`awk '{ a[$7]++ } END { for (i in a) print " " a[i] " " i }' /var/log/nginx/access.log | sort -rn`

or, if you have GNU awk:

`awk '{ a[$7]++ } END { PROCINFO["sorted_in"] = "@val_num_desc"; for (i in a) print " " a[i] " " i }' /var/log/nginx/access.log`


You'll be pointing out that [ is a built-in command, next. (-:


It's also a binary in /bin (or a symlink because of /usr merge) and it's silly that the article tries to view [ in a pager.




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

Search: