by jasongi · 4mo ago · 0 comments
Program A might accept a file as the last positional arg. Program B might accept it as a named arg, where the name/flag could be anything from --input or -f or --file etc.
But a program will read from STDIN, which all good unix programs do, then piping cat into it works every time. I can write the cat foo.txt part before I even know what command I'm piping it into.
You can start your pipeline with a file redirection: " <input_file prog1 | prog2 | prog3 | ... | progN >output_file".
I've probably lost 10ms * 1E5 of my life from the extra PID. But, probably would lose more in the context switch.
cat expected.1376| sed '1,4d' | rg '(\t\d)\t.*' --replace '$1' | column -ts $'\t'
I was figuring shit out along the way and it'd be pretty annoying to adjust which command gets the filename throughout that process.You know what? I'll tell you another thing I do that's similar:
SELECT * FROM whatever WHERE true
AND last_modified > 123
AND otherfield NOT NULL
Always bugged me that you say WHERE for the first one and AND thereafter, so if I'm poking around the database trying to create actionable insights for key stakeholders at the speed of business just as I was above with the text file, I like to be able to futz and delete/add clauses as I see fit just as I do pipeline stages."Oh no, it spawns another process!!" Again, nobody cares.
"< file.txt somecommand | othercommand | anothercommand"
There is never any need for "cat".
When such a pipeline is used repeatedly in a script, the time for executing the redundant process "cat" can easily add up to a noticeable delay.
> "cat" can easily add up to a noticeable delay.
If you have a slow script, you will have more useful places to optimize than removing calls to cat.