Mailinglist Archive: opensuse (2430 mails)

< Previous Next >
Re: [opensuse] BASH - brain teaser, can it be done without a pipe?
  • From: "David C. Rankin" <drankinatty@xxxxxxxxxxxxxxxxxx>
  • Date: Wed, 23 Apr 2008 01:35:47 -0500
  • Message-id: <480ED8C3.6080701@xxxxxxxxxxxxxxxxxx>
David Haller wrote:
Hello,


Easy: awk and perl were created for this kind of stuff.

awk '$3 > tmax { tmax = $3; }
END { printf "Maximum temperature was: %.1f °C\n", tmax;
}' cputemp.log

More elaborate with the following input:

====
20080419 02:32 63.3 C
20080419 02:34 64.1 C
20080419 02:36 63.9 C
20080419 02:39 65.3 C
20080419 02:42 64.2 C
20080419 02:49 65.32 C
20080419 02:53 65.3 C
20080419 03:02 64.2 C
====

$ awk '
$3 > tmax {
tmax = $3;
tdate = $1;
ttime = $2;
}
END {
printf "Maximum temperature was: %.1f °C on %s %s\n",
tmax, tdate, ttime;
}' cputemp.log
Maximum temperature was: 65.3 °C on 20080419 02:49

HTH,
-dnh


Thanks Anders, David, Brian and David!

I don't now where you guys get this stuff, but it is great. I have learned 4 new ways to skin this cat. Thanks again. One of the days I'll snatch a pebble or two.


--
David C. Rankin, J.D., P.E.
Rankin Law Firm, PLLC
510 Ochiltree Street
Nacogdoches, Texas 75961
Telephone: (936) 715-9333
Facsimile: (936) 715-9339
www.rankinlawfirm.com
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >