Hacker News new | ask | show | jobs
by mkl 11 days ago
For interactive use like these examples I think this is terrible advice. cat is very helpful because it fits into pipelines like every other command. For example:

Take a look at the start of a file:

  head file
Filter for things:

  head file | grep ... 
Reformat, remove unwanted stuff, etc.:

  head file | grep ... | sed ...
Do things or dry run echo based on each line:

  head file | grep ... | sed ... | while read a; do ...; done
It all looks good so we change head to cat to run it on the whole file:

  cat file | grep ... | sed ... | while read a; do... ; done
Yes you can technically change "head file |" to "< file" but why bother? That's changes in two places and navigating between them instead of just <alt-d> cat.

Same is true for other workflows. E.g. if you start with one of these supposedly better commands like "wc -l < file" (why isn't that just "wc -l file"?):

  wc -l < file
Oh wait, we don't want every line, just ones matching a pattern. We could change it to

  wc -l <(grep ... file) 
or

  grep -c ... file
which are both more work than just adding to an existing cat-based pipeline, where we just replace cat with "grep ...":

  grep ... file | wc -l
If we need to also match another pattern or whatever this pipeline approach is better then too.