home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10212 < prev    next >
Encoding:
Text File  |  1992-08-20  |  1.4 KB  |  43 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!magna!doc
  3. From: doc@magna.com (Matthew J. D'Errico)
  4. Subject: Re: Simple AWK question.....
  5. Message-ID: <BtAAI4.1AD@magna.com>
  6. Organization: Magna Software Corporation
  7. References: <l96frkINNsom@phad.hsc.usc.edu>
  8. Date: Thu, 20 Aug 1992 13:22:51 GMT
  9. Lines: 32
  10.  
  11. In article <l96frkINNsom@phad.hsc.usc.edu> you write:
  12. >I'd like to reference the environment variable PWD inside an awk script.  I
  13. >wrote the following simple script to sum bytes in any given directory, and
  14. >would like the output to say:  Total Bytes in /usr/lib: 1024000 (1 MB).
  15. > [...]
  16. >......................
  17. >
  18. >#    sums directory bytes (BSD)
  19. >
  20. >ls -l | awk  '
  21.  
  22.     WrkDir = "'$PWD'"
  23. >
  24. >        {sum += $4}
  25. >
  26. >    END    {printf "Total Bytes in Directory:  %10d   (%7.1f  MB)\n", sum, sum/1024000}
  27.  
  28.     END    {printf "Total Bytes in $WrkDir:  %10d   (%7.1f  MB)\n", sum, sum/1024000}
  29.  
  30. -----------------------------
  31. Give that a try...
  32.  
  33. -- Doc
  34. +-------------------------------+---------------------------------------+
  35. |    Matthew J. D'Errico    | DOMAIN:    mderrico@magna.com    |
  36. | Magna Software Corporation    | uucp:        uunet!magna!mderrico    |
  37. |     275 Seventh Avenue    | CompuServe:    70744,3405        |
  38. |     20th Floor        +---------------------------------------+
  39. |    New York, NY   10001    |    Voice    : 212 / 727 - 6737    |
  40. |        USA            |    Fax    : 212 / 691 - 1968    |
  41. +-------------------------------+---------------------------------------+
  42.  
  43.