News for hackers. Stuff that matters.
Re:Natural Language Processing in Bash by kwhitefoot on Sunday April 21, 2024 @03:48AM (#40103904)
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
Re:Natural Language Processing in Bash by sambazi on Sunday April 21, 2024 @04:29AM (#40104052)
true, though i think the code style focuses on readability
Re:Natural Language Processing in Bash by massimo-nazaria on Sunday April 21, 2024 @10:51AM (#40106185)
Exactly
Re:Natural Language Processing in Bash by olejorgenb on Sunday April 21, 2024 @06:32AM (#40104563)
I 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)

Re:Natural Language Processing in Bash by massimo-nazaria on Sunday April 21, 2024 @10:50AM (#40106173)
Great comment, strongly agree.
Re:Natural Language Processing in Bash by _wire_ on Sunday April 21, 2024 @07:31AM (#40104829)
It'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.
Re:Natural Language Processing in Bash by massimo-nazaria on Sunday April 21, 2024 @10:51AM (#40106182)
Strongly agree.
Re:Natural Language Processing in Bash by jwilk on Sunday April 21, 2024 @01:56PM (#40107731)
It's certainly a useless use of /dev/stdin.