WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline mocore

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

i found some talk about programing history at
 https://web.archive.org/web/20130209012208/http://www.leancrew.com/all-this/2011/12/more-shell-less-egg/

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

Quote
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})

 8)


Offline jazzbiker

  • Jr. Member
  • **
  • Posts: 84
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.

Offline mocore

  • Full Member
  • ***
  • Posts: 219
Re: more shell,...
« Reply #2 on: August 10, 2019, 07:12:14 AM »

 wrt "The Yoda of Silicon Valley" ::)
there is a interesting profile @ nytimes.com/2018/12/17/science/donald-knuth-computers-algorithms-programming.html


Offline PDP-8

  • Sr. Member
  • ****
  • Posts: 469
Re: more shell,...
« Reply #3 on: August 17, 2019, 02:26:11 AM »
The author of that article wonders why McIlroy used sed in the last line instead of head - wondering if head hadn't been invented yet.

McIlroy, (the guy who proposed pipes in the mid 60's, but finally got it implemented in unix early on in the 70's with constant brow-beating Ken about it) wouldn't use head or tail - being a Berkeleyism convenience short-circuiting the toolbox concept.

Heh, if you want head or tail, use sed commands to do it and perhaps alias it by those names, or make it an executable script.  Remove those from busybox and relive the true spirit of the day!

Kind of similar to the cat -v "bloat" . :)


« Last Edit: August 17, 2019, 02:30:18 AM by PDP-8 »
That's a UNIX book! - cool  -- Garth