Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!decwrl!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.questions Subject: Re: Printer Accounting File Parsing Message-ID: <9108@jpl-devvax.JPL.NASA.GOV> Date: 11 Aug 90 00:02:38 GMT References: <24110@adm.BRL.MIL> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 56 In article <24110@adm.BRL.MIL> BKEHOE%widener@pucc.princeton.edu writes: : : Here's something that should be simple to solve..it can be in anything (C/ : awk/shell/whatever). : I need to parse down the results of the printer accounting file into a total : for each user for that 2-week or month-long period of time, and send mail to : those users that've gone above 50 pages saying something like "Calm down". : I've been futzing in awk but can't seem to pull it off -- and in C my string : manipulation seems to be off (admittedly I haven't spent a *lot* of time : hacking it out). : ... : It'd be nice if I could assess the # of pages they print off of each client : too, but that may be overkill. No problem. ---------- CUT HERE ---------- #!/usr/bin/perl $THRESHOLD = 50; while (<>) { ($pages, $wherewho) = split(' '); ($where, $who) = split(/:/, $wherewho); $sum{$who} += $pages; $client{$who} .= "$where " unless $clientsum{$wherewho}; $clientsum{$wherewho} += $pages; } foreach $who (keys %sum) { next if $sum{$who} < $THRESHOLD; @clients = sort split(' ', $client{$who}); $breakdown = ''; if (@clients >= 2) { $breakdown = "Breakdown:\n\tMachine \tPages\n"; foreach $client (@clients) { $breakdown .= sprintf("\t%-16s%5d\n", $client, $clientsum{"$client:$who"}); } } open(MAIL,"|/bin/mail $who") || die "Can't run mail: $!\n"; print MAIL <