Live data from Hacker News

The useful use of cat

mrmr.io

91–100 of 113 posts

Re: The useful use of cat

#91
post #71

Earlier quoted context omitted.

Or just use grep file?

The point is you do not know if file is a stream, an archive, too big, currently empty or just contains bad data for your current test. So using cat file is a way to standardize debugging or make development easier.

Also, you can replace cat with pv to get a progress bar. Or replace cat with socat to stream stdin from a network socket. Etc etc.

Re: The useful use of cat

#92
post #7

Using `cat file.txt | ...` has always felt more natural to me, so I still use it. If I need to build a long command I've been using the excellent `up` tool to do it, e.g. `cat file.txt | up` https://github.com/akavel/up

> Using `cat file.txt | ...` has always felt more natural to me

Use whatever you prefer¹, but if what you care for is the logic of reading left to right, you can do so without `cat` by doing instead `¹ It’s absurd this needs to be spelled out, but here we are.

Re: The useful use of cat

#93
post #92
post #7

Using `cat file.txt | ...` has always felt more natural to me, so I still use it. If I need to build a long command I've been using the excellent `up` tool to do it, e.g. `cat file.txt | up` https://github.com/akavel/up

> Using `cat file.txt | ...` has always felt more natural to me Use whatever you prefer¹, but if what you care for is the logic of reading left to right, you can do so without `cat` by doing instead ` ¹ It’s absurd this needs to be spelled out, but here we are.

They're saying they find "cat" more natural than "<" which I can understand. Unless you regularly use "<", it's probably easier to remember "cat" and it's more self-documenting.

Re: The useful use of cat

#95
post #50

Earlier quoted context omitted.

` 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).

I usually interpret `command fileB` as meaning "shove fileA into this command, and shove output into fileB". The "arrows" make visual sense this way. ` at least visually gives off the impression that it's sending the command's output to the left (changing the prompt, perhaps?)

If only we could do `fileA> command >fileb` for the ultimate readability...

Re: The useful use of cat

#96

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.

By that argument, no one would ever learn anything.

Everything in programming is new to someone at some point. There are useful features few people know about, and you get them to be widespread and familiar by using and talking about them.

Just because you only ever learned about `for` loops doesn’t mean you shouldn’t understand and use `map`.

Re: The useful use of cat

#97
post #92

Earlier quoted context omitted.

> Using `cat file.txt | ...` has always felt more natural to me Use whatever you prefer¹, but if what you care for is the logic of reading left to right, you can do so without `cat` by doing instead ` ¹ It’s absurd this needs to be spelled out, but here we are.

They're saying they find "cat" more natural than "<" which I can understand. Unless you regularly use "<", it's probably easier to remember "cat" and it's more self-documenting.

> They're saying they find "cat" more natural than "I don’t think that’s what they’re saying. I think they’re making the point that going left to right with the file first is what makes sense to them, as opposed to `... < file.txt`.

Re: The useful use of cat

#98
post #92
post #7

Using `cat file.txt | ...` has always felt more natural to me, so I still use it. If I need to build a long command I've been using the excellent `up` tool to do it, e.g. `cat file.txt | up` https://github.com/akavel/up

> Using `cat file.txt | ...` has always felt more natural to me Use whatever you prefer¹, but if what you care for is the logic of reading left to right, you can do so without `cat` by doing instead ` ¹ It’s absurd this needs to be spelled out, but here we are.

I don't care about fancy 'I want to type 'cat'.

The visual imagery of summoning a cute cat to do my POSIX sorcery trumps all else.

Re: The useful use of cat

#99
post #97

Earlier quoted context omitted.

They're saying they find "cat" more natural than "<" which I can understand. Unless you regularly use "<", it's probably easier to remember "cat" and it's more self-documenting.

> They're saying they find "cat" more natural than " I don’t think that’s what they’re saying. I think they’re making the point that going left to right with the file first is what makes sense to them, as opposed to `... < file.txt`.

You're assuming they don't know about `<file.txt ...` That may be the case, but I can still see an argument for "cat" being more natural than "<" in this context.

Re: The useful use of cat

#100
post #97

Earlier quoted context omitted.

> They're saying they find "cat" more natural than " I don’t think that’s what they’re saying. I think they’re making the point that going left to right with the file first is what makes sense to them, as opposed to `... < file.txt`.

You're assuming they don't know about `<file.txt ...` That may be the case, but I can still see an argument for "cat" being more natural than "<" in this context.

> You're assuming they don't know about `And you’re assuming they do. It’s safe to assume at least one person reading the comment won’t know about the feature, the information is useful to more than that poster.

> but I can still see an argument for "cat" being more natural than "You’re also assuming I don’t understand that sentiment. That has nothing to do with my original post. I don’t care what you use, do whatever makes you happiest. I was merely offering an alternative that would still satisfy what I perceived to be the original point (command piping left to right) to share knowledge, I was in no way criticising their method or saying they shouldn’t use it.

This is a useless conversation.

Post reply on HN