[H-GEN] Humbug Obfusticated Awk Code Contest?

Michael King m.king at ozemail.com.au
Mon Dec 29 16:57:55 EST 1997


I don't know if anyone else notice the flaw in this code, submitted a while back.

***   awk '{ if ( NF == 4 ) { M = (1200*$2 + 60*$3 + $4); } else { M = (60*$2 + $3); } print $1 " " M }' | ***
                                   ^^^^
There is 1440 minutes in a day not 1200.
echo "24*60" | bc
1440


Anthony Towns wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
>
> Hiya all,
>
> After Fuzzy's Most Excellent talk, I thought I'd add my voice to the
> "Awk can do anything Perl can do, and better" chorus.
>
> Today's lesson is entitled ``Unreadable code is easy with Awk''
>
> last |
>   awk '/[012][0-9]:[0-5][0-9] - [012][0-9]:[0-5][0-9]/ {print $1 " " $NF}' |
>   sed 's/[:+]/ /g;s/[()]//g' |
>   awk '{ if ( NF == 4 ) { M = (1200*$2 + 60*$3 + $4); } else { M = (60*$2 + $3); } print $1 " " M }' |
>   sort |
>   awk 'BEGIN { X = "" } { if ( X == $1 ) { for ( i = 2; i <= NF; i++ ) printf( " %s", $i ) } else { if ( X != "" ) print ""; printf( "%s", $0 ); X = $1 } }' |
>   awk '{ printf( "%-8s\t", $1 ); M=0; for ( i = 2; i <= NF; i++ ) { M += $i } H = int(M / 60); D=int(H/24); H %= 24; M %= 60; printf( "%4d+%02d:%02d\n", D, H, M ) }' |
>  sort +.10 -r
>
> What's it do?
>
> Tells you the cumulative amount of time each of the system's users has
> logged on for.
>
> How does it do it?
>
> Consider that your homework for the day.
>
> Cheers,
> aj
>
> - --
> Anthony Towns <aj at humbug.org.au> <http://azure.humbug.org.au/~aj/>
> I don't speak for anyone save myself. PGP encrypted mail preferred.
>
> ``NT, Networking, Security. Pick any two (you can't have all three).''
>         -- _The Twelve Networking Truths_, RFC 1925, paraphrased
>
> -----BEGIN PGP SIGNATURE-----
> Version: 2.6.3ia
> Charset: ascii
> Comment: Key available at http://student.uq.edu.au/~s343676/aj_key.asc
>
> iQCVAwUBNJPfO+RRvX9xctrtAQG+2QQAtZydGd3JOLvFRkKzSmsMd+W7k7KNPjhL
> 7MAc29cIDBvYD/8lkgciUAqJzJp9j84deGTwKESvmxI3vJICl23KVoTqXRqqKvst
> DQe9klK5SKHvg7NiB8YauWD4v6fOVj7VSwE44JORrho5OyE0U4gZrXeOdYZXHHy0
> FKObof5MvNA=
> =o3wS
> -----END PGP SIGNATURE-----
>
> ----------------------- HUMBUG General List --------------------------------
> echo "unsubscribe general" | mail majordomo at humbug.org.au # To Unsubscribe


-------------- next part --------------
A non-text attachment was scrubbed...
Name: vcard.vcf
Type: text/x-vcard
Size: 398 bytes
Desc: Card for Michael King
URL: <http://lists.humbug.org.au/pipermail/general/attachments/19971230/11944438/attachment.vcf>


More information about the General mailing list