Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language AWK

(correct text)

Date:11/03/07
Author:OsamuAoki
URL:http://people.debian.org/~osamu
Comments:2
Info:n/a
Score: (3.03 in 182 votes)
#!/usr/bin/awk -f
#   awk version of 99 bottles of beer
#    by Whitey (whitey@netcom.com) - 06/05/95
#   updated to create correct text including the ending
#    by Osamu Aoki (osamu@debian.org) - 20007-11-04

BEGIN { 
   for(i = 99; i >= 0; i--) {
      print ubottle(i), "on the wall,", lbottle(i) "."
      print action(i), lbottle(inext(i)), "on the wall."
      print
   }
}
function ubottle(n) {
   return sprintf("%s bottle%s of beer", n ? n : "No more", n - 1 ? "s" : "")
}
function lbottle(n) {
   return sprintf("%s bottle%s of beer", n ? n : "no more", n - 1 ? "s" : "")
}
function action(n) {
   return sprintf("%s", n ? "Take one down and pass it around," : \
                            "Go to the store and buy some more,")
}
function inext(n) {
   return n ? n - 1 : 99
}

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
bottled versionWilhelm Weske11/16/080
2Arnold Robbins01/25/080

Comments

>>  jasavi said on 04/12/09 01:54:05

jasavi Tested on Fedora 8, it works. Sat Apr 11 2009, 19:20

>>  cpan said on 08/13/10 00:14:42

cpan Nice. Awk is an underutilized and under-appreciated language.

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: