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:
  1. cat /path/to/my/file.log |  
  2. grep filter |  
  3. sed 'something, I don't really use sed a lot' |  
  4. grep filter_again |  
  5. 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.
  1. cat /path/to/my/file.log | # read data from file  
  2. grep filter |              # run a filter on file contents  
  3. sed 'something, I don't really use sed a lot' | #change file contents  
  4. grep filter_again |        # run another filter on contents  
  5. lp                         # send to printer  

Compare to this:
  1. grep filter cat |          # read data from file AND run a filter on file contents  
  2. sed 'something, I don't really use sed a lot' | #change file contents  
  3. grep filter_again |        # run another filter on contents  
  4. 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