3 ms·
I'm always surprised to see "Useless Use of Cat Award"[1] recipients in such compilations. I know there is some debate[2] around UUOC, but somehow this sort of
by miles 13y ago
I'm always surprised to see "Useless Use of Cat Award"[1] recipients in such compilations. I know there is some debate[2] around UUOC, but somehow this sort of thing (from the top-voted answer) seems wasteful:
cat access.log | egrep -o 'acct_id=[0-9]+' | cut -d= -f2 | sort | uniq -c | sort -rn
Why not just
egrep -o 'acct_id=[0-9]+' access.log | cut -d= -f2 | sort | uniq -c | sort -rn ?
Perhaps for these sorts of tutorials, the former is clearer on first inspection. But I can't help agreeing with bahamat[3] that it's about "forming good habits and discouraging bad ones".
[1] http://partmaps.org/era/unix/award.html#cat http://partmaps.org/era/unix/award.html#cat
[2] http://superuser.com/questions/323060/what-is-the-general-consensus-on-useless-use-of-cat http://superuser.com/questions/323060/what-is-the-general-co...
[3] http://superuser.com/a/323167/38084 http://superuser.com/a/323167/38084
- claudius 13y agoAt least I tend to build pipes iteratively, that is, I start with ‘cat foo’, then add grep/cut/sort/uniq as I see fit, checking the output during each stage. This, at least, happens if I plan to stay in one line for that particular job – if I write a proper script, I’ll take care to use grep properly.