Simple AWK question.....

Simple AWK question.....

Post by Rich Pind » Fri, 21 Aug 1992 15:45:08



I'd like to reference the environment variable PWD inside an awk script.  I
wrote the following simple script to sum bytes in any given directory, and
would like the output to say:  Total Bytes in /usr/lib: 1024000 (1 MB).

Thanks for you help

......................

#       sums directory bytes (BSD)

ls -l | awk  '

                {sum += $4}

        END     {printf "Total Bytes in Directory:  %10d   (%7.1f  MB)\n", sum, sum/1024000}

--

Rich

 
 
 

Simple AWK question.....

Post by Michael Staa » Fri, 21 Aug 1992 19:19:26



Quote:>I'd like to reference the environment variable PWD inside an awk script.  I
>wrote the following simple script to sum bytes in any given directory, and
>would like the output to say:  Total Bytes in /usr/lib: 1024000 (1 MB).
>Thanks for you help
>......................
>#   sums directory bytes (BSD)

What about

$ echo Total kbytes in $PWD: `du -s .`

This works under AIX 3.1.5 with ksh and I hope under other BSD like OS, too.
Under SYS V like OS you'll get twice the amount of kB, which is weird,
but ...

So long
Michael
--
Michael Staats
Theoretische Tieftemperaturphysik
Universitaet Gesamthochschule Duisburg


 
 
 

Simple AWK question.....

Post by Matthew J. D'Erri » Fri, 21 Aug 1992 22:22:51



Quote:>I'd like to reference the environment variable PWD inside an awk script.  I
>wrote the following simple script to sum bytes in any given directory, and
>would like the output to say:  Total Bytes in /usr/lib: 1024000 (1 MB).
> [...]
>......................

>#   sums directory bytes (BSD)

>ls -l | awk  '

        WrkDir = "'$PWD'"

Quote:

>            {sum += $4}

>    END     {printf "Total Bytes in Directory:  %10d   (%7.1f  MB)\n", sum, sum/1024000}

        END     {printf "Total Bytes in $WrkDir:  %10d   (%7.1f  MB)\n", sum, sum/1024000}

-----------------------------
Give that a try...

-- Doc
+-------------------------------+---------------------------------------+

| Magna Software Corporation    | uucp:         uunet!magna!mderrico    |
|     275 Seventh Avenue        | CompuServe:   70744,3405              |
|        20th Floor             +---------------------------------------+
|    New York, NY   10001       |       Voice   : 212 / 727 - 6737      |
|           USA                 |       Fax     : 212 / 691 - 1968      |
+-------------------------------+---------------------------------------+

 
 
 

Simple AWK question.....

Post by Guy Harr » Sat, 22 Aug 1992 03:37:58


Quote:>This works under AIX 3.1.5 with ksh and I hope under other BSD like OS, too.
>Under SYS V like OS you'll get twice the amount of kB, which is weird,
>but ...

Err, AIX 3.2, at least, isn't "BSD-like" in that regard, it's System
V-like, not surprisingly; its "du" reports the number of 512-byte
chunks, not the number of 1024-byte chunks.

SV-like "du" commands don't *report* the number of kB, they report the
number of half-kB.

 
 
 

Simple AWK question.....

Post by Tom Christianse » Sat, 22 Aug 1992 04:23:32



:SV-like "du" commands don't *report* the number of kB, they report the
:number of half-kB.

Can anyone explain WTF POSIX.2 decided that utilities should report
things in demikilobytes instead of real k which we all are more
likely to think in?  

--tom
--

Unix is like a toll road on which you have to stop every 50 feet to
pay another nickel.  But hey!  You only feel 5 cents poorer each time.

 
 
 

Simple AWK question.....

Post by Tony Lu » Sat, 22 Aug 1992 17:20:02



>Can anyone explain WTF POSIX.2 decided that utilities should report
>things in demikilobytes instead of real k which we all are more
>likely to think in?  

Suppose you have a file system with zillions of little tiny files (for
example /usr/spool/news).  You figure that you can keep the disk
usage down (and thus the expiry time up) by making the filesystem with
a 512 byte block size (or fragment size).  Now, if you have a "du" that
only thinks in Kbytes, it won't give you the right answer when you want
to know how much disk space will be freed up if you blow away all of
"alt/useless/bogus/groups".


 
 
 

Simple AWK question.....

Post by Tom Christianse » Sat, 22 Aug 1992 23:16:58



:>Can anyone explain WTF POSIX.2 decided that utilities should report
:>things in demikilobytes instead of real k which we all are more
:>likely to think in?  
:
:Suppose you have a file system with zillions of little tiny files (for
:example /usr/spool/news).  You figure that you can keep the disk
:usage down (and thus the expiry time up) by making the filesystem with
:a 512 byte block size (or fragment size).  Now, if you have a "du" that
:only thinks in Kbytes, it won't give you the right answer when you want
:to know how much disk space will be freed up if you blow away all of
:"alt/useless/bogus/groups".

Are you saying that du's answer should vary depending on f/s geometry???

--tom
--

    "We don't care.  We don't have to.  We're the Phone Company."

 
 
 

Simple AWK question.....

Post by Guy Harr » Sun, 23 Aug 1992 02:54:50


 >:Suppose you have a file system with zillions of little tiny files (for
 >:example /usr/spool/news).  You figure that you can keep the disk
 >:usage down (and thus the expiry time up) by making the filesystem with
 >:a 512 byte block size (or fragment size).  Now, if you have a "du" that
 >:only thinks in Kbytes, it won't give you the right answer when you want
 >:to know how much disk space will be freed up if you blow away all of
 >:"alt/useless/bogus/groups".
 >
 >Are you saying that du's answer should vary depending on f/s geometry???

Either that, or he's saying he can't figure out how to make a "du" that
calculates the sizes in 512-byte units, but prints the result out in
Kbytes....

 
 
 

Simple AWK question.....

Post by Stan Ryckm » Sun, 23 Aug 1992 02:52:27



|>:SV-like "du" commands don't *report* the number of kB, they report the
|>:number of half-kB.
|>
|>Can anyone explain WTF POSIX.2 decided that utilities should report
|>things in demikilobytes instead of real k which we all are more
|>likely to think in?  
|>
|>--tom

Maybe they're demiwits?  :-)

Stan.
--
This .signature has expired.  Call 1-900-YOU-FOOL to find out why.

 
 
 

Simple AWK question.....

Post by Kim Chr. Mads » Mon, 24 Aug 1992 05:21:09




>:SV-like "du" commands don't *report* the number of kB, they report the
>:number of half-kB.
>Can anyone explain WTF POSIX.2 decided that utilities should report
>things in demikilobytes instead of real k which we all are more
>likely to think in?  

Because it's a political committee before anything else, with
participants from the largest vendors, who like a status-quo approach
(if we standardize what is we don't have to change anything) and many
of the participants are SysV people... (sigh)...

Along the lines of standardisation (sp?) why can't the various
committees realize that a few (able) people can do a lot better, once
all arguments have been said, instead of having large groups of people
trying to agree on something they possible never will agree on because
of political issues.

                                        Kim Chr. Madsen

 
 
 

1. Simple awk question

I am trying to build on an example in the O'Reilly book on 'sed'
and 'awk', but not getting anywhere. The example is the script
'filesum' starting on page 160.

Even the following script fails:

=====

#!/bin/csh -f

ls -l $* | nawk '{   \
           BEGIN { print "BYTES" } ;  \
               {  sum += $5 ;  \
                  ++filenum ;  \
                  print $5  }    \
           }'
======

even though it works without the BEGIN line. I have very
limited experience with 'awk' (just simple one liners').
Checking various websites did not help. Any pointers
on where to look up on the use of 'awk' within C shell
scripts would be welcome.

thanks

--


                         Remove 'bounceback' for email address

2. mod_perl

3. simple awk question

4. Test

5. trouble with rsh and afs

6. a simple awk question

7. SCSI Card Not Found During Installation (Future Domain 1680)

8. Simple awk question

9. simple awk question

10. A simple question regarding shell scripts and awk

11. sed/awk - 2 simple question :-)

12. Simple ? awk question.