sed -e 's/ \+/\n/' words.txt | uniq -c sed -e 's/ \+/\n/' words.txt | uniq -cOnce you commit to a programming language instead of shell, then you have various types of IO to worry about. What you want might be in an array or list, a file, a database table, an xml file, or the response from a web service. Typically, you either need to write a decent chunk of code for each of these sources, either for abstraction or for marshaling.
With LINQ, all you need is a change in the upfront handling, and you can reuse the same comprehension logic across all the different data sources. This is a pretty nice deal, all things considered.
And really, one way of looking at adding comprehensions like this to languages is to make programming in languages more like chaining together code in a shell script -- something that programming in traditional Algol-descended languages is not normally like at all.
This is not an article about trivial word counting. This an article about mathematical abstractions behind all batch data processing (unix pipes included).
Just because we already know how to count small numbers of words in bash doesn't mean we can't learn anything from this article.
sed 's/ \+/\n/' words.txt | tr A-Z a-z | sort | uniq -c
And to get the top five, you'd need another sort: sed 's/ \+/\n/' words.txt | tr A-Z a-z | sort | uniq -c | sort -gr | head -5
Where the delimiters of interest go where the space is in the sed expression. Of course, I can never remember what strange regex syntax sed uses, so I have spend 5 minutes trying to puzzle through man page.Also, it all depends on what you value; cryptic one liners definitely will get you geek cred, but working with other people not as smart as you will not be fun when having to explain and maintain code like that.
Of course, you may never have to worry about that.
So, in a way, yes, it is the same, but that is exactly the point.
curl http://weather.yahoo.com/united-states/california/san-jose-2488042/ | sed '/Current conditions/s/.*id="yw-temp">\([0-9]\+\).*/\1/'
It may be fragile, but any method of extracting data out of HTML is going to be fragile when the provider changes design or layout.A tiny bit of knowledge of grep, sed, and awk, and other simple unix text utilities such as join, comm, cut, paste, goes a long long way.
The tl;dr I got from the article was LINQ is effective at working with sets of data; not just sets of text data from a text file.
I think maybe we're not shooting at the same baskets though (basketball reference, apologies if you're not from US); I'm trying to write software applications, not shell scripts.
curl 'http://weather.yahooapis.com/forecastrss?w=615702&u=c' | \
xmlstarlet sel -N 'y=http://xml.weather.yahoo.com/ns/rss/1.0' \
-t -m '//y:forecast' -v '@text'
edit: corrected xml lineLINQ, on the other hand, can work with arbitrary runtime objects and arbitrary backend implementations. Haskell's still cooler, though.