Most active commenters
  • jonnycomputer(3)

←back to thread

2039 points Gadiguibou | 12 comments | | HN request time: 1.465s | source | bottom
Show context
klausa ◴[] No.36491947[source]
`pbcopy` and `pbpaste` are one of my most-loved in the list.

Dealing with some minified json, switching to iTerm, doing `pbpaste | json_pp | pbcopy` and having a clean output is _so_ nice.

replies(28): >>36492008 #>>36492015 #>>36492028 #>>36492101 #>>36492108 #>>36492229 #>>36492265 #>>36492890 #>>36492953 #>>36493037 #>>36493127 #>>36493336 #>>36493457 #>>36493802 #>>36494023 #>>36494242 #>>36494325 #>>36495379 #>>36495894 #>>36496866 #>>36497033 #>>36497293 #>>36497589 #>>36497973 #>>36498181 #>>36498558 #>>36498586 #>>36535798 #
omginternets ◴[] No.36492265[source]
If I had a nickel for each `cat foo.json | jq | pbcopy`, I'd be a rich man :)
replies(1): >>36492862 #
maleldil ◴[] No.36492862[source]
That's a useless use of cat. You can use `jq . foo.json | pbcopy` or `jq < foo.json | pbcopy`.
replies(6): >>36492960 #>>36493144 #>>36493370 #>>36494558 #>>36495101 #>>36495918 #
jdbartee ◴[] No.36492960[source]
Speaking for myself, the first form is more natural- even if it’s a useless cat, because I’m always cat-ing files to see their structure. Then progressively tacking on different transforms. And then finally putting it in whatever I want as output.

It’s so ingrained, I’m more likely than not to just write it out that way even when I know exactly what I’m doing from the onset.

replies(5): >>36493350 #>>36493487 #>>36494377 #>>36496238 #>>36497947 #
1. jonnycomputer ◴[] No.36493487[source]
Yes, this iterative procedure is often why "useless" cats get put into it. It's a very effective way of processing regular text information.

e.g.

I need to grab some info from textfile.txt to use as arguments to a function.

cat textfile.txt

looks like its comma delimited.

cat textfile.txt | cut -d, -f 2-5

ah, its the third and fourth column i need

cat textfile.txt | cut -d, -f 3-4 | grep '123456'

perfect

cat textfile.txt | cut -d, -f 3-4 | grep 123456 | tr , ' '

myfunc $(cat textfile.txt | cut -d, -f 3-4 | grep 123456 | tr , ' ')

replies(1): >>36494503 #
2. gumby ◴[] No.36494503[source]
> cat textfile.txt

> looks like its comma delimited.

Interesting; why wouldn't you use `head`? Who knows how big textfile.txt is?

replies(4): >>36494862 #>>36494869 #>>36494913 #>>36495260 #
3. rovr138 ◴[] No.36494862[source]
`file` will tell you too
replies(1): >>36494911 #
4. ◴[] No.36494869[source]
5. jonnycomputer ◴[] No.36494911{3}[source]
Won't tell you the delimiter.
6. yrro ◴[] No.36494913[source]
Don't forget to pipe head into 'cat -v'... that text file could contain _anything_!
replies(2): >>36495824 #>>36496116 #
7. jonnycomputer ◴[] No.36495260[source]
generally, speaking, if you don't have an idea of how big the file is, or it would take up too much real-estate on your terminal window, sure. 100%. It was just an example.

lot's of times we sort of know what we are working with, but don't remember the particulars especially

8. gunapologist99 ◴[] No.36495824{3}[source]
Thank you for pointing this out! This is much safer.
9. lelandbatey ◴[] No.36496116{3}[source]
I really recommend folks use "less" over cat, especially keyboard oriented folks. Different terminal emulators don't always have the scroll behavior I want, not do they always allow me to search the file I'm looking at. "less" does all those things, in nearly every environment no matter the terminal emulator, and has other wonderful options to boot (chop long lines so they don't wrap can be nice for logs, line numbers can be VITAL, etc).

I still uselessly use cat though, it's such a nice way to build a pipeline.

replies(2): >>36498355 #>>36499959 #
10. jmhammond ◴[] No.36498355{4}[source]
My useless cat is that I always use `cat file | less` when I could just `less file`.

I've been typing cat for over 25 years. Old habits die hard.

11. rconti ◴[] No.36499959{4}[source]
I hate that when I use `less`, then quit, the output goes away.
replies(1): >>36508860 #
12. LgWoodenBadger ◴[] No.36508860{5}[source]
You can run "less -X" for that, but it may have other problems depending on how you use less (e.g. scrolling up, etc.)