Live data from Hacker News

The useful use of cat

mrmr.io

41–50 of 113 posts

Re: The useful use of cat

#41
> Some people insist that we should never use a cat

Rather, people argue against useless use of cat, which is different. Personally, I'd never argue against it on the command-line even though some do. It's once you commit your pipeline to a script where you may as well remove it.

There are also suitable uses of cat that I don't think anyone would argue against. Besides the obvious use of outputting one or more files, it's also often used with here docs.

Re: The useful use of cat

#43

if you prefer to use cat just to read your pipeline from left to right, you can just start your command with file redirection. It doesn't have to be at the end of the command. this works in bash too, but if you're using zsh, there're a couple of nice shortcuts on it's own works as more file and > file ... ... ^D allows you to put something into the file quickly without firing up the editor. Though > file will give yo…

If I saw It would give me pause. If I saw cat file | grep ... I would understand it instantly, as would any other Unix user. Therefore the latter is better code.

Or just use

    grep  file?

Re: The useful use of cat

#48

I'm a believer in the ditt-k-pow, DTTCPW, the Dumbest Thing That Could Possibly Work. What, exactly, are the arguments against `cat`?

The argument is that it's redundant because 'cat f | head' does the same as 'head f'

I don't mind either way but I find starting with a cat and reading LTR to be very easy to understand.

Re: The useful use of cat

#49

Earlier quoted context omitted.

I'm not sure I have ever used tac for real. Could you give an example?

When you want to tail a file, but you want it in descending order and you’re not sure how much of it you want: tac file | less

I guess the difference is that I expect things to read top to bottom, so I'd do that as

  less foo.log
  G

Re: The useful use of cat

#50

if you prefer to use cat just to read your pipeline from left to right, you can just start your command with file redirection. It doesn't have to be at the end of the command. this works in bash too, but if you're using zsh, there're a couple of nice shortcuts on it's own works as more file and > file ... ... ^D allows you to put something into the file quickly without firing up the editor. Though > file will give yo…

If I saw It would give me pause. If I saw cat file | grep ... I would understand it instantly, as would any other Unix user. Therefore the latter is better code.

`idiomatic, but when I see it I think it makes perfect sense. It puts the pipeline "in order", starting with redirection from the input (and presumably ending with redirection to the output, if not stdout).
Post reply on HN