Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2011/12/02

'cat' considered not useless

Consider this:
cat /path/to/my/file.log |
grep filter |
sed 'something, I don't really use sed a lot' |
grep filter_again |
lp

Many would write this off as "useless use of cat". I don't think so. I mean, functionally, sure. But it isn't all functional.
cat /path/to/my/file.log | # read data from file
grep filter |              # run a filter on file contents
sed 'something, I don't really use sed a lot' | #change file contents
grep filter_again |        # run another filter on contents
lp                         # send to printer

Compare to this:
grep filter cat |          # read data from file AND run a filter on file contents
sed 'something, I don't really use sed a lot' | #change file contents
grep filter_again |        # run another filter on contents
lp                         # send to printer

You have now overloaded grep and if you want to remove it, you now have more editing than reading a line.

Friend of the blog Patrick says that this use of cat is just as useless as comments. I tend to agree.

No comments:

Post a Comment