home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / qtawk / histogrm.exp < prev    next >
Text File  |  1990-04-23  |  763b  |  27 lines

  1. # histogram - AWK, page 70 (Note short program at bottom of page run from
  2. # command line to create random.txt with following command
  3. # QTAwk "BEGIN{for(i=1;i<=200;i++)print(int(101*rand()));}" >random.txt
  4. # and
  5. # QTAwk -fhistogrm.exp random.txt
  6. # or
  7. # QTAwk "BEGIN{for(i=1;i<=200;i++)print(int(101*rand()));}" | QTAwk -fhistogrm.exp
  8. #
  9. # also can use AWKPLUS porgram random.exp
  10. # QTAwk -random.exp | QTAwk -fhistogrm.exp
  11. #
  12. # input: numbers between 0 and 100
  13. # output: histogram of deciles
  14. #
  15.     {
  16.     x[int($1/10)]++;
  17.     }
  18. END    {
  19.     for ( i = 0 ; i < 10 ; i++ )
  20.       printf(" %2d - %2d: %3d %s\n", 10*i, 10*i+9, x[i], rep(x[i],"*"));
  21.     }
  22. function rep(n,s, t) { #return string of n s's
  23. #     while ( n-- > 0 ) t = t s;
  24. #     return t;
  25.     return copies(s,n);
  26.     }
  27.