4 ms·
Why the fuck on earth, people cat and pip stuff to grep ? grep cat take files from args !
by papey 9y ago
Why the fuck on earth, people cat and pip stuff to grep ? grep cat take files from args !
- yorwba 9y agoI cat files into programs that can take their inputs both from stdin and a given file, although I know people call that "useless". I do it because it makes my pipelines more uniform, by keeping the direction of data flow from left to right. It also makes it easier to insert additional processing steps, or changing the input from a file to the output of a program. Maybe I'm a fool for writing Bash like Forth, but I prefer it that way.
- asicsp 9y agoyou can still do `< test.txt grep ...` see https://en.wikipedia.org/wiki/Cat_(Unix)#UUOC_.28Useless_Use_Of_Cat.29 https://en.wikipedia.org/wiki/Cat_(Unix)#UUOC_.28Useless_Use... >Beyond other benefits, the input redirection forms allow command to perform random access on the file, whereas the cat examples do not. This is because the redirection form opens the file as the stdin file descriptor which command can fully access, while the cat form simply provides the data as a stream of bytes. commands like `sort` are optimized to handle large input file and how would you do `grep -l 'foo' *.txt` if you use `cat`? or `awk 'NR==FNR{a[$1]; next} $1 in a' file1 file2` or `grep -Fxf file1 file2` and so on....