3 ms·
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 ta
by jdbartee 3y ago
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.
- paulddraper 3y agoYou could consider < foo.json jq | pbcopy
- jonnycomputer 3y agoYes, 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 , ' ')
- gumby 3y ago> cat textfile.txt > looks like its comma delimited. Interesting; why wouldn't you use `head`? Who knows how big textfile.txt is?
- rovr138 3y ago`file` will tell you too
- jonnycomputer 3y agoWon't tell you the delimiter.
- deleted 3y ago[deleted]
- yrro 3y agoDon't forget to pipe head into 'cat -v'... that text file could contain _anything_!
- gunapologist99 3y agoThank you for pointing this out! This is much safer.
- lelandbatey 3y agoI 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.
- jmhammond 3y agoMy 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.
- rconti 3y agoI hate that when I use `less`, then quit, the output goes away.
- LgWoodenBadger 3y agoYou can run "less -X" for that, but it may have other problems depending on how you use less (e.g. scrolling up, etc.)
- jonnycomputer 3y agogenerally, 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
- jamespullar 3y agoI've been using bat as a cat replacement for a while now. It includes paging, syntax highlighting, line numbers, and is generally very performant. https://github.com/sharkdp/bat https://github.com/sharkdp/bat
- patrec 3y agoIf you're using zsh, you can just replace any instance of $ cat somefile ... with $ <somefile ... For bash, this only works if you have at least one `|`.
- ddingus 3y agoI did this last time I saw it come up and was surprised! Doing it makes perfect sense in hindsight. Neato!
- fastaguy88 3y agoAs a scientist who cares about reproducibility, the big difference between the "useless cat" and providing the input file name on the command line is that, in the latter case, the program can capture that file name and reproduce it. That is harder when using stdin. Many of my programs and scripts start output with the line: # cmd arg1 arg2 arg3 ... and simply echo back lines that start with '#'. That way, I have an internal record of the program that was run and the data file that was read (as well as previous parts of the analysis chain). And, 'R' ignores lines starting with '#', so the record is there, but does not affect later analyses.