WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: more shell,...  (Read 169 times)

Offline mocore

  • Full Member
  • ***
  • Posts: 213
more shell,...
« on: May 02, 2019, 03:16:38 PM »

i found some talk about programing history at

and interesting example of the method + explanation 

Code: [Select]
tr -cs A-Za-z '\n' |
tr A-Z a-z |
sort |
uniq -c |
sort -rn |
sed ${1}q

If you are not a UNIX adept, you may need a little explanation, but not much, to understand this pipeline of processes.
The plan is easy:

    Make one-word lines by transliterating the complement (-c) of the alphabet into newlines (note the quoted newline), and squeezing out (-s) multiple newlines.
    Transliterate upper case to lower case.
    Sort to bring identical words together.
    Replace each run of duplicate words with a single representative and include a count (-c).
    Sort in reverse (-r) numeric (-n) order.
    Pass through a stream editor; quit (q) after printing the number of lines designated by the script’s first parameter (${1})


Offline jazzbiker

  • Jr. Member
  • **
  • Posts: 54
Re: more shell,...
« Reply #1 on: May 02, 2019, 09:59:37 PM »
Knuth is like himself and nobody else. He proposed such task knowing well how it can be done in bash, i expect. But he wanted to show, how beautyfuly can be wriiten this simple task using his programming approach. Maybe he wanted to tell, that small can't be beautiful?
TeX is smth beatiful, but in the same time very big one, too.