News for hackers. Stuff that matters.
Re:macOS command-line tools you might not know about by jonnycomputer on Tuesday June 27, 2023 @10:37AM (#36493487)
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 , ' ')

Re:macOS command-line tools you might not know about by gumby on Tuesday June 27, 2023 @11:45AM (#36494503)
> cat textfile.txt

> looks like its comma delimited.

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

Re:macOS command-line tools you might not know about by jonnycomputer on Tuesday June 27, 2023 @12:38PM (#36495260)
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

Re:macOS command-line tools you might not know about by yrro on Tuesday June 27, 2023 @12:16PM (#36494913)
Don't forget to pipe head into 'cat -v'... that text file could contain _anything_!
Re:macOS command-line tools you might not know about by gunapologist99 on Tuesday June 27, 2023 @01:11PM (#36495824)
Thank you for pointing this out! This is much safer.
Re:macOS command-line tools you might not know about by lelandbatey on Tuesday June 27, 2023 @01:32PM (#36496116)
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.

Re:macOS command-line tools you might not know about by jmhammond on Tuesday June 27, 2023 @04:42PM (#36498355)
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.

Re:macOS command-line tools you might not know about by rconti on Tuesday June 27, 2023 @07:07PM (#36499959)
I hate that when I use `less`, then quit, the output goes away.
Re:macOS command-line tools you might not know about by LgWoodenBadger on Wednesday June 28, 2023 @12:31PM (#36508860)
You can run "less -X" for that, but it may have other problems depending on how you use less (e.g. scrolling up, etc.)
Re:macOS command-line tools you might not know about by rovr138 on Tuesday June 27, 2023 @12:13PM (#36494862)
`file` will tell you too
Re:macOS command-line tools you might not know about by jonnycomputer on Tuesday June 27, 2023 @12:16PM (#36494911)
Won't tell you the delimiter.