Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'What's next' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
What's next
Authored by: mario_grgic on Jan 07, '09 03:24:19PM

Really? Simplicity yes. But power no. Let's look at a trivial example. Let's say I ask you how many Friday 13th there each year from 2000 to 2100?

How would a GUI user solve that. Open iCal and count manually?

What if I said "and you have 40 seconds to solve it!". Now what? Game over for the GUI user.

But for someone proficient in UNIX and CLI (touch typing first, then good in vi and then UNIX) you would do something like this:

$ ncal 2009

that gives you something like this:

2009
January February March April
Mo 5 12 19 26 2 9 16 23 2 9 16 23 30 6 13 20 27
Tu 6 13 20 27 3 10 17 24 3 10 17 24 31 7 14 21 28
We 7 14 21 28 4 11 18 25 4 11 18 25 1 8 15 22 29
Th 1 8 15 22 29 5 12 19 26 5 12 19 26 2 9 16 23 30
Fr 2 9 16 23 30 6 13 20 27 6 13 20 27 3 10 17 24
Sa 3 10 17 24 31 7 14 21 28 7 14 21 28 4 11 18 25
Su 4 11 18 25 1 8 15 22 1 8 15 22 29 5 12 19 26
May June July August
Mo 4 11 18 25 1 8 15 22 29 6 13 20 27 3 10 17 24 31
Tu 5 12 19 26 2 9 16 23 30 7 14 21 28 4 11 18 25
We 6 13 20 27 3 10 17 24 1 8 15 22 29 5 12 19 26
Th 7 14 21 28 4 11 18 25 2 9 16 23 30 6 13 20 27
Fr 1 8 15 22 29 5 12 19 26 3 10 17 24 31 7 14 21 28
Sa 2 9 16 23 30 6 13 20 27 4 11 18 25 1 8 15 22 29
Su 3 10 17 24 31 7 14 21 28 5 12 19 26 2 9 16 23 30
September October November December
Mo 7 14 21 28 5 12 19 26 2 9 16 23 30 7 14 21 28
Tu 1 8 15 22 29 6 13 20 27 3 10 17 24 1 8 15 22 29
We 2 9 16 23 30 7 14 21 28 4 11 18 25 2 9 16 23 30
Th 3 10 17 24 1 8 15 22 29 5 12 19 26 3 10 17 24 31
Fr 4 11 18 25 2 9 16 23 30 6 13 20 27 4 11 18 25
Sa 5 12 19 26 3 10 17 24 31 7 14 21 28 5 12 19 26
Su 6 13 20 27 4 11 18 25 1 8 15 22 29 6 13 20 27

Ok, so now you want all the lines that for Fridays. Easy, hit ESC k A and type | grep "^Fr" like

ncal | grep "^Fr"

that now prints:

Fr 2 9 16 23 30 6 13 20 27 6 13 20 27 3 10 17 24
Fr 1 8 15 22 29 5 12 19 26 3 10 17 24 31 7 14 21 28
Fr 4 11 18 25 2 9 16 23 30 6 13 20 27 4 11 18 25

That's slightly better. Ok now let's print only the 13 from these lines

ncal 2009 | grep "^Fr" | perl -na -e 'foreach (@F) { print "$_\n" if /13/}'

This now gives us:
13
13
13

i.e the number of Friday 13th in year 2009. Nice. Let's count how many there are

Hit ESC k A type | wc -l to get the command

ncal 2009 | grep "^Fr" | perl -na -e 'foreach (@F) { print "$_\n" if /13/}' | wc -l

which prints:

3

Nice now let's decorate what we are printing:

printf "Number of Friday 13th in 2009: "; ncal 2009 | grep "^Fr" | perl -na -e 'foreach (@F) { print "$_\n" if /13/}' | wc -l

which outputs:

Number of Friday 13th in 2009: 3

Excellent. So now let's add the final step and print this for all years from 2000 to 2100

for year in {2000..2100}; do printf "Number of Friday 13th in $year: "; ncal $year | grep "^Fr" | perl -na -e 'foreach (@F) { print "$_\n" if /13/}' | wc -l; done

which prints:

Number of Friday 13th in 2000: 1
Number of Friday 13th in 2001: 2
Number of Friday 13th in 2002: 2
Number of Friday 13th in 2003: 1
Number of Friday 13th in 2004: 2
Number of Friday 13th in 2005: 1
.
.
.
Number of Friday 13th in 2097: 2
Number of Friday 13th in 2098: 1
Number of Friday 13th in 2099: 3
Number of Friday 13th in 2100: 1
$

which is what we wanted. A real UNIX power user can do this in 40 seconds ( 20 or so to think and the rest to type it).

"When I was little I looked at pictures. When I grew up I learned to read and write". Same goes for computer use. Power users type and read. While novices click on pictures.



[ Reply to This | # ]
What's next
Authored by: palahala on Jan 10, '09 04:35:26AM

So how does this single problem prove "Stop worshipping the CLI. It isn't the best solution to every problem" wrong?



[ Reply to This | # ]