4 ms·
Here is the code from words.sh cat /dev/stdin\ | tr 'A-Z' 'a-z'\ | sed 's/[^a-z\.]/ /g'\ | tr -s ' .'\ | sed 's/\./ \. /g'\ | tr -s ' '\ | tr ' ' '\n'
by kwhitefoot 3y ago
Here is the code from words.sh
cat /dev/stdin\
| tr 'A-Z' 'a-z'\
| sed 's/[^a-z\.]/ /g'\
| tr -s ' .'\
| sed 's/\./ \. /g'\
| tr -s ' '\
| tr ' ' '\n'\
| grep -v '^$';
exit 0;
Isn't that a Useless Use Of Cat? It works without the cat and the first pipe character.
Similarly:
cat moby-dick.txt | ./words.sh > words.txt
This could be:
< moby-dick.txt ./words.sh > words.txt
cat is for concatenating files
- sambazi 3y agotrue, though i think the code style focuses on readability
- massimo-nazaria 3y agoExactly
- olejorgenb 3y agoI don't get the anticat crusaders. The overhead of a `cat` command surly is entirely negligible ? cat moby-dick.txt | ./words.sh > words.txt I much more readable to me than < moby-dick.txt ./words.sh > words.txt In the `tr` case I kinda agree, but there is a niceness to the flow when all the transformation steps are aligned like that. > cat is for concatenating files The real world disagrees. It's nice to know that `< file` work though. If the input of an pipeline is what's varying writing it like `{ command1 | command 2 } < input.txt` make it slightly more convenient iterating on since changing the last word is more accessible after getting the command from history. (turning on noclobber to avoid accidentally typing `>` to be safe)
- massimo-nazaria 3y agoGreat comment, strongly agree.
- _wire_ 3y agoIt's been wisely pointed out elsewhere that pre-pending an empty cat saves the need to futz with the first stage syntax when reusing the pipeline. It serves a syntactic function.
- massimo-nazaria 3y agoStrongly agree.
- jwilk 3y agoIt's certainly a useless use of /dev/stdin.