(Inaugurating a new category which will be kind of my own dailty wtf)
A pretty well known matter is how some tools can be abused. Usually, it is cat
or grep
. Typical examples include the following two:
cat foo | grep bar
grep bar foo | awk '{print $2}'
Obviously, the first one can be reduced to:
grep bar foo
and the second, to:
awk '/bar/ {print $2}' foo
awk
and sed
are often part of the reason grep
gets abused, because a lot of people don't know the latter form above or its sed
equivalent. They don't know they could restrict the match on a specific column, too, which could be important in some cases.
Anyways, a few months ago, I saw the most beautiful short piece of combined useless use of something I've ever seen, which also happens to be a pretty unusual type:
more $file | wc | awk '{print $1}'
Not only does it use more
where even cat
, while still being useless, would be a better choice, but it also manages to use awk
where wc
could take an option to achieve the same goal.
Yes, the above can be simplified as:
wc -l < $file
We never found who was responsible for this nicety.