Re: [SLUG] Silly shell challenge

2003-03-17 Thread James Gregory
On Tue, 2003-03-18 at 18:19, Jeff Waugh wrote:

> Your mission: To work out what it's doing, why you'd be stupid enough to
> want to do it, and then how to do it better. It has to be in shell, and it
> has to handle decimals! :-)

You're a bad, bad man. I have been known to waste days reducing such
expressions, but not today! Just one simplification to make it spawn 1
less process:

awk '{if(/bogomips/){ print "+" $3 }}' < /proc/cpuinfo | tr -d '\n' |
cut -c 2- | blah blah blah

James.

-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-17 Thread James Gregory
On Tue, 2003-03-18 at 18:19, Jeff Waugh wrote:
> want to do it, and then how to do it better. It has to be in shell, and it

Wait a moment, when you say "better" do you mean increase or decrease
the number of processes needed to do it? Can I call postgres?

James.


-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread John Ferlito
On Tue, Mar 18, 2003 at 06:19:26PM +1100, Jeff Waugh wrote:
> So,
> 
> Here's some silly shell...
> 
>   $ grep bogomips /proc/cpuinfo | awk '{ print "+" $3 }' | tr -d '\n' | cut -c 2- | 
> bc
>   6121.06
> 
> Your mission: To work out what it's doing, why you'd be stupid enough to
> want to do it, and then how to do it better. It has to be in shell, and it
> has to handle decimals! :-)

Too easy. You just need to learn some more awk Mr Waugh :) You don't even need
to fork at all.

$ awk '{ if(/bogomips/){ SUM+=$3 } } END {print SUM}' /proc/cpuinfo


-- 
John
http://www.inodes.org/
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread mlh
On Tue, 18 Mar 2003 18:19:26 +1100
Jeff Waugh <[EMAIL PROTECTED]> wrote:

> Here's some silly shell...
> 
>   $ grep bogomips /proc/cpuinfo | awk '{ print "+" $3 }' | tr -d '\n' | cut -c 2- | 
> bc
>   6121.06
> 
> Your mission: To work out what it's doing, why you'd be stupid enough to
> want to do it, and then how to do it better. It has to be in shell, and it
> has to handle decimals! :-)


  awk '/bogomips/ {print $3}' /proc/cpuinfo

or am I missing something?

--
Matt

-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Jessica Mayo
Can't resist a shell challenge, can I?... :)

On Tue, 18 Mar 2003, Jeff Waugh wrote:
> Here's some silly shell...
>
>   $ grep bogomips /proc/cpuinfo | awk '{ print "+" $3 }' | tr -d '\n' | cut -c 2- | 
> bc
>   6121.06

Very silly. awk + tr + cut is highly redundant and bc is not installed on
my system. :)

Here's something simpler that produces the same output for a single
processor without bc...:

$ grep bogomips /proc/cpuinfo | sed 's/[^0-9.]*//'

... although my system only says 729.08 :)

> Your mission: To work out what it's doing, why you'd be stupid enough to
> want to do it, and then how to do it better. It has to be in shell, and it
> has to handle decimals! :-)

Given that bc or dc are not guaranteed to be installed, I use expr
instead, but doing decimal calculations involves fixed-point maths.

all that given, the following works properly on a multi-cpu system:

$ expr 0 `sed -e 's/[0-9][0-9.]*/&000/' -e
 's/^bogomips[^0-9.]*\([0-9]*\)\(.\([0-9][0-9][0-9]\)\)*.*/+ \1\3/' -e
 '/^[^+]*$/d' /proc/cpuinfo` | sed 's/[0-9][0-9][0-9]$/.&/'

... be careful of the back-ticks and single quotes. I tend to use single
quotes to give my sed scripts better protection from the shell. the $ is
guaranteed not to be misinterpreted that way.


Ok, it's nasty, but it does it in 3 processes and with shell utilities
that will always be available.

Basically, Sed appends extra zeroes to all numbers, converts bogomips line
to a plus sign and a fixed three decimal places, and throws away the rest.
I then use expr to add the bogomips values to zero and put the decimal
point back in with a second sed.


now to why?:

To tell the user how long something's going to take, of course! :)
It's a slackware tradition to estimate how long something is going to take
in BogomipSeconds... the number never changes, but as you get more
Bogomips, you end up with less seconds. This chunk would give the shell
script a way of turning that abstract number into a time that an ordinary
user will understand. :)



Do I get the prize? :)

-- Jess
(Everything with a grin :)



-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


RE: [SLUG] Silly shell challenge

2003-03-18 Thread Theo Julienne
How about:

grep bogomips /proc/cpuinfo | awk '{ print $3 }'

---
Kind Regards,

Theo Julienne 

-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread CaT
On Tue, Mar 18, 2003 at 06:33:44PM +1100, James Gregory wrote:
> On Tue, 2003-03-18 at 18:19, Jeff Waugh wrote:
> 
> > Your mission: To work out what it's doing, why you'd be stupid enough to
> > want to do it, and then how to do it better. It has to be in shell, and it
> > has to handle decimals! :-)
> 
> You're a bad, bad man. I have been known to waste days reducing such
> expressions, but not today! Just one simplification to make it spawn 1
> less process:
> 
> awk '{if(/bogomips/){ print "+" $3 }}' < /proc/cpuinfo | tr -d '\n' |
> cut -c 2- | blah blah blah

I think I win. :)

grep '^bogomips[[:space:]]*: ' /proc/cpuinfo | sed -e 's/^.*: //'

Now... depending on just how anal you wanna be, the grep pattern could
just be 'bogomips'. You could also replace the sed with cut -c 12- if
you don't mind the leading space. ie:

grep -F bogomips /proc/cpuinfo | cut -c 12-

:)

-- 
"Other countries of course, bear the same risk. But there's no doubt his
hatred is mainly directed at us. After all this is the guy who tried to
kill my dad."
- George W. Bush Jr, 'President' of Regime of the United States
  September 26, 2002 (from a political fundraiser in Huston, Texas)

-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Damien Gardner Jnr
From: "Jeff Waugh" <[EMAIL PROTECTED]>
>   $ grep bogomips /proc/cpuinfo | awk '{ print "+" $3 }' | tr -d '\n' |
cut -c 2- | bc
>   6121.06
>
> Your mission: To work out what it's doing, why you'd be stupid enough to
> want to do it, and then how to do it better. It has to be in shell, and it
> has to handle decimals! :-)

Looks like it's grabbing the bogomips value (and adding a + in front of),
cutting the \n off it, removing the +, then passing it to bc to shove the \n
back in... Why you'd want to do it? no idea :)

better like this:

$ grep bogomips /proc/cpuinfo | sed 's/.*: \(.*\).*$/\1/'
1101.00

?

--
Damien Gardner Jnr
VK2TDG. Dip EE. StudIEAust
Home: [EMAIL PROTECTED] -  http://www.rendrag.net/
Play: [EMAIL PROTECTED]  -  http://pinegap.net/
Work: [EMAIL PROTECTED]   -  http://www.isa.net.au/

-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread John Ferlito
On Tue, Mar 18, 2003 at 09:19:58PM +1100, [EMAIL PROTECTED] wrote:
> On Tue, 18 Mar 2003 18:19:26 +1100
> Jeff Waugh <[EMAIL PROTECTED]> wrote:
> 
>   awk '/bogomips/ {print $3}' /proc/cpuinfo
> 
> or am I missing something?
Yes he's trying to add up the bogomips for multiple CPU's, stumped me
for a bit to.


-- 
John
http://www.inodes.org/
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Jessica Mayo
On Tue, 18 Mar 2003, John Ferlito wrote:
> On Tue, Mar 18, 2003 at 06:19:26PM +1100, Jeff Waugh wrote:
> > Here's some silly shell...
> >
> >   $ grep bogomips /proc/cpuinfo | awk '{ print "+" $3 }' | tr -d '\n' | cut -c 2- 
> > | bc
> >   6121.06
> >
> > Your mission: To work out what it's doing, why you'd be stupid enough to
> > want to do it, and then how to do it better. It has to be in shell, and it
> > has to handle decimals! :-)
>
> Too easy. You just need to learn some more awk Mr Waugh :) You don't even need
> to fork at all.
>
> $ awk '{ if(/bogomips/){ SUM+=$3 } } END {print SUM}' /proc/cpuinfo

... on second thoughts. awk is better. I bow to your awk-lord-ness :)

I'd argue that this is no better than using perl, but awk _is_ expected to
be portable without installing extra... (perl is usually optional)

... but why didn't you answer the other questions?! :)

-- Jess.
(Everything with a grin :)

-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread mlh
On Tue, 18 Mar 2003 21:40:44 +1100
John Ferlito <[EMAIL PROTECTED]> wrote:

> On Tue, Mar 18, 2003 at 09:19:58PM +1100, [EMAIL PROTECTED] wrote:
> > On Tue, 18 Mar 2003 18:19:26 +1100
> > Jeff Waugh <[EMAIL PROTECTED]> wrote:
> > 
> >   awk '/bogomips/ {print $3}' /proc/cpuinfo
> > 
> > or am I missing something?
> Yes he's trying to add up the bogomips for multiple CPU's, stumped me
> for a bit to.
> 

Ah-hah.

Ok, John F wins.


--
Matt
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread mlh
On Tue, 18 Mar 2003 21:02:38 +1100
John Ferlito <[EMAIL PROTECTED]> wrote:

> $ awk '{ if(/bogomips/){ SUM+=$3 } } END {print SUM}' /proc/cpuinfo

Except no need for if, '/pattern/ {action}' is idiomatic awk:

$ awk '/bogomips/ { SUM+=$3 } } END {print SUM}' /proc/cpuinfo
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Jeff Waugh


> On Tue, 18 Mar 2003 21:02:38 +1100
> John Ferlito <[EMAIL PROTECTED]> wrote:
> 
> > $ awk '{ if(/bogomips/){ SUM+=$3 } } END {print SUM}' /proc/cpuinfo
> 
> Except no need for if, '/pattern/ {action}' is idiomatic awk:
> 
> $ awk '/bogomips/ { SUM+=$3 } } END {print SUM}' /proc/cpuinfo

Heh, first and second prize to you guys, once you worked out the finer
detail. :-)

  $ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
  6121.06

Nice one!

- Jeff

-- 
   "Science helps a lot, but people built perfectly good brick walls long   
   before they knew why cement works." - Alan Cox   
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Phil Scarratt
You lot really do have too much time on your hands:)

Jeff Waugh wrote:


On Tue, 18 Mar 2003 21:02:38 +1100
John Ferlito <[EMAIL PROTECTED]> wrote:

$ awk '{ if(/bogomips/){ SUM+=$3 } } END {print SUM}' /proc/cpuinfo
Except no need for if, '/pattern/ {action}' is idiomatic awk:

$ awk '/bogomips/ { SUM+=$3 } } END {print SUM}' /proc/cpuinfo


Heh, first and second prize to you guys, once you worked out the finer
detail. :-)
  $ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
  6121.06
Nice one!

- Jeff



--
Phil Scarratt
Draxsen Technologies
IT Contractor/Consultant
0403 53 12 71
--
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Jeff Waugh


> You lot really do have too much time on your hands:)

This is a SLUG tradition! :-)

- Jeff

-- 
  Acts of random.   
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread mkraus
How about just:

awk '{if(/bogomips/){print $3}}' < /proc/cpuinfo | bc 6121.06


(NB. Adding a + with awk and removing the newline with tr, only to reverse 
both of those with cut is futile.)

Although just:

echo "File 6210.06 is unavailable."

Would probably be the simplest ;)

All the best...

Mike
---
Michael S. E. Kraus
Administration
Capital Holdings Group (NSW) Pty Ltd
p: (02) 9955 8000




James Gregory <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
18/03/2003 06:33 PM

 
To: 
cc: Penguinillas <[EMAIL PROTECTED]>
    Subject:    Re: [SLUG] Silly shell challenge


On Tue, 2003-03-18 at 18:19, Jeff Waugh wrote:

> Your mission: To work out what it's doing, why you'd be stupid enough to
> want to do it, and then how to do it better. It has to be in shell, and 
it
> has to handle decimals! :-)

You're a bad, bad man. I have been known to waste days reducing such
expressions, but not today! Just one simplification to make it spawn 1
less process:

awk '{if(/bogomips/){ print "+" $3 }}' < /proc/cpuinfo | tr -d '\n' |
cut -c 2- | blah blah blah

James.

-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug



-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread mkraus
G'day...

Why would you want to add up the bogomips of all processors though?

If it was to estimate total processing power it wouldn't be accurate - 
After all 2 x 1GHz processors != 1 x 2GHz processor and bogomips are an 
approximation themselves.

Curious...

Mike
---
Michael S. E. Kraus
Administration
Capital Holdings Group (NSW) Pty Ltd
p: (02) 9955 8000
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Jeff Waugh


> Why would you want to add up the bogomips of all processors though?

Because whoever has the most bogomips at the end, wins.

;-)

- Jeff

-- 
 It's not just a song! It's a document of my life!  
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Jeff Waugh


> Why would you want to add up the bogomips of all processors though?

(It was a silly idea for a SLUG shell challenge, with a bit of a brain
teaser about Linux features to boot.) 

- Jeff

-- 
 "jwz? no way man, he's my idle" - James Wilkinson  
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Steve Kowalik
At 10:52 am, Wednesday, March 19 2003, Jeff Waugh mumbled:
> Because whoever has the most bogomips at the end, wins.
> 
Okay, I'll bite.

[EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
7982.27

What do I win? A good kick in the pants?

-- 
   Steve
 the only reason I have paperclips is to straighten them and stab 
things
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Ben Leslie
On Wed, 19 Mar 2003, Steve Kowalik wrote:

> At 10:52 am, Wednesday, March 19 2003, Jeff Waugh mumbled:
> > Because whoever has the most bogomips at the end, wins.
> > 
> Okay, I'll bite.
> 
> [EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
> 7982.27
> 
> What do I win? A good kick in the pants?

fwiw, that script (and i guess none of the others) work on my Linux (2.5.59):

"""
[EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo

"""

However,

"""
[EMAIL PROTECTED]:~$ awk '/BogoMIPS/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
3189.74


I'm not sure if there is a case insensitive search in awk.

(And while I don't win the BogoMIPS, how about:

[EMAIL PROTECTED]:~$ grep MemTotal /proc/meminfo 
MemTotal: 16583232 kB
)

Benno
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread mkraus
Hrmm... Maybe the joy of having 2 P4 processors on your Linux box...

Very nice...

Mike
---
Michael S. E. Kraus
Administration
Capital Holdings Group (NSW) Pty Ltd
p: (02) 9955 8000




Steve Kowalik <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
19/03/2003 11:18 AM

 
To: SLUG List <[EMAIL PROTECTED]>
cc: 
Subject:    Re: [SLUG] Silly shell challenge


At 10:52 am, Wednesday, March 19 2003, Jeff Waugh mumbled:
> Because whoever has the most bogomips at the end, wins.
> 
Okay, I'll bite.

[EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' 
/proc/cpuinfo
7982.27

What do I win? A good kick in the pants?

-- 
   Steve
 the only reason I have paperclips is to straighten them and 
stab 
things
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug



-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Colin Humphreys
On Wed, Mar 19, 2003 at 11:18:40AM +1100, Steve Kowalik wrote:
> At 10:52 am, Wednesday, March 19 2003, Jeff Waugh mumbled:
> > Because whoever has the most bogomips at the end, wins.
> > 
> Okay, I'll bite.
> 
> [EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
> 7982.27
> 
I can go a long way the other way:

([EMAIL PROTECTED])-(Debian GNU/Linux 3.0 sparc)-(11:28am Wed Mar 19)-(~)
$ awk '/BogoMips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
39.83

Do I lose?

-Colin
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Steve Kowalik
At 11:30 am, Wednesday, March 19 2003, [EMAIL PROTECTED] mumbled:
> Hrmm... Maybe the joy of having 2 P4 processors on your Linux box...
> 
Pentium 4's are brain-damaged, and can't be used in an SMP configuration.
Intel want you to buy Xeons for SMP.

[EMAIL PROTECTED]:~$ egrep '(model name|MHz)' /proc/cpuinfo
model name  : AMD Athlon(tm) Processor
cpu MHz : 2000.103
model name  : AMD Athlon(tm) Processor
cpu MHz : 2000.103

> Very nice...
> 
Yeah, I think so too. :-)

-- 
   Steve
 how about MTBF?  scsi will once again rise high and rule with a metal
fist
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Anthony Wood
On Wed, Mar 19, 2003 at 11:25:57AM +1100, Ben Leslie wrote:
> On Wed, 19 Mar 2003, Steve Kowalik wrote:
> 
> > At 10:52 am, Wednesday, March 19 2003, Jeff Waugh mumbled:
> > > Because whoever has the most bogomips at the end, wins.
> > > 
> > Okay, I'll bite.
> > 
> > [EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
> > 7982.27
> > 
> > What do I win? A good kick in the pants?
> 
> fwiw, that script (and i guess none of the others) work on my Linux (2.5.59):
> 
> """
> [EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
> 
> """
> 
> However,
> 
> """
> [EMAIL PROTECTED]:~$ awk '/BogoMIPS/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
> 3189.74
> 
> 
> I'm not sure if there is a case insensitive search in awk.
> 
> (And while I don't win the BogoMIPS, how about:
> 
> [EMAIL PROTECTED]:~$ grep MemTotal /proc/meminfo 
> MemTotal: 16583232 kB

Looks like it's time to patch the kernel code for /proc/meminfo
to output something more readable, like 15 Gb.

And break everything which parses it :-)

-- 
Woody
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Anthony Wood
On Wed, Mar 19, 2003 at 11:25:57AM +1100, Ben Leslie wrote:
> On Wed, 19 Mar 2003, Steve Kowalik wrote:
> 
> > At 10:52 am, Wednesday, March 19 2003, Jeff Waugh mumbled:
> > > Because whoever has the most bogomips at the end, wins.
> > > 
> > Okay, I'll bite.
> > 
> > [EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
> > 7982.27
> > 
> > What do I win? A good kick in the pants?
> 
> fwiw, that script (and i guess none of the others) work on my Linux (2.5.59):
> 
> """
> [EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
> 
> """
> 
> However,
> 
> """
> [EMAIL PROTECTED]:~$ awk '/BogoMIPS/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
> 3189.74
> 
> 
> I'm not sure if there is a case insensitive search in awk.

 awk '/BogoMips/i { SUM+=$3 } END {print SUM}' /proc/cpuinfo

-- 
Woody
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Tony Green
On Wed, 2003-03-19 at 11:41, Anthony Wood wrote:
>  awk '/BogoMips/i { SUM+=$3 } END {print SUM}' /proc/cpuinfo
# awk '/BogoMips/i { SUM+=$3 } END {print SUM}' /proc/cpuinfo
slug-chat
#

How odd.  ;-)

-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread scott
[EMAIL PROTECTED] wrote on 19-03-2003 11:35:16 AM:

> At 11:30 am, Wednesday, March 19 2003, [EMAIL PROTECTED] 
mumbled:
> > Hrmm... Maybe the joy of having 2 P4 processors on your Linux box...
> > 
> Pentium 4's are brain-damaged, and can't be used in an SMP 
configuration.
> Intel want you to buy Xeons for SMP.
> 
> [EMAIL PROTECTED]:~$ egrep '(model name|MHz)' /proc/cpuinfo
> model name  : AMD Athlon(tm) Processor
> cpu MHz : 2000.103
> model name  : AMD Athlon(tm) Processor
> cpu MHz : 2000.103
> 
> > Very nice...
> > 
> Yeah, I think so too. :-)
> 
Damn, wish I had the smp kernel booted on my Dual Xeon 1.8ghz with 
hyperthreading :)
Alas some of the modules arn't configured for it. (give me time :)

Cheers,

Scott
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Jamie Wilkinson
This one time, at band camp, Steve Kowalik wrote:
>At 10:52 am, Wednesday, March 19 2003, Jeff Waugh mumbled:
>> Because whoever has the most bogomips at the end, wins.
>> 
>Okay, I'll bite.
>
>[EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
>7982.27

[EMAIL PROTECTED] root]# zsh
juggernaut# a=`for i in ${(f)"$(http://spacepants.org/jaq.gpg
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Jamie Wilkinson
This one time, at band camp, Jeff Waugh wrote:
>So,
>
>Here's some silly shell...
>
>  $ grep bogomips /proc/cpuinfo | awk '{ print "+" $3 }' | tr -d '\n' | cut -c 2- | bc
>  6121.06
>
>Your mission: To work out what it's doing, why you'd be stupid enough to
>want to do it, and then how to do it better. It has to be in shell, and it
>has to handle decimals! :-)

echo $(($(grep bogomips /proc/cpuinfo|cut -f2 -d:|sed 's/$/ +/') 0))

grep bogomips /proc/cpuinfo|sed -e's/^.*://' -e's/^/+ /'| xargs echo 0|bc

-- 
[EMAIL PROTECTED]   http://spacepants.org/jaq.gpg
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Jamie Wilkinson
This one time, at band camp, Jeff Waugh wrote:
>It has to be in shell,

Awk isn't shell.  zsh is shell.

a=`for i in ${(f)"$(http://spacepants.org/jaq.gpg
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Steve Kowalik
At 11:50 am, Wednesday, March 19 2003, Jamie Wilkinson mumbled:
> I tried to get it down to one line, but zsh complained about bad
> substitutions with the backticks, despite the manpage saying it'd do command
> substitutions within a $(()) expression.
> 
It should be able to do that. I know bash handles $() inside $(()).

-- 
   Steve
* walters wonders if "fun" and "XFree86 source" can go together...
 walters : If it includes the words "printed" and "burning"
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Jeff Waugh


>  awk '/BogoMips/i { SUM+=$3 } END {print SUM}' /proc/cpuinfo

I tried that too, but didn't post it:

  $ echo -e "BogoMIPS : 10\nBogoMIPS : 10\nEstoy : 10" | awk '/bogomips/i { SUM+=$3 } 
END {print SUM}'
  30

- Jeff

-- 
   "If the Internet really wanted to become sentient, it probably could."   
   - Raph Levien
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-18 Thread Norman Gaywood
On Wed, Mar 19, 2003 at 11:18:40AM +1100, Steve Kowalik wrote:
> At 10:52 am, Wednesday, March 19 2003, Jeff Waugh mumbled:
> > Because whoever has the most bogomips at the end, wins.
> > 
> Okay, I'll bite.
> 
> [EMAIL PROTECTED]:~$ awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
> 7982.27

Nope. No kick in the pants. That's coming to me so far:

turing 3:04pm ~ % awk '/bogomips/ { SUM+=$3 } END {print SUM}' /proc/cpuinfo
25421.4

-- 
Norman Gaywood -- School of Mathematical and Computer Sciences
University of New England, Armidale, NSW 2351, Australia
[EMAIL PROTECTED] http://turing.une.edu.au/~norm
Phone: +61 2 6773 2412 Fax: +61 2 6773 3312
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug


Re: [SLUG] Silly shell challenge

2003-03-19 Thread Peter Chubb
> "Jessica" == Jessica Mayo <[EMAIL PROTECTED]> writes:

Jessica> On Tue, 18 Mar 2003, John Ferlito wrote:
>> On Tue, Mar 18, 2003 at 06:19:26PM +1100, Jeff Waugh wrote: >
>> Here's some silly shell...
>> >
>> > $ grep bogomips /proc/cpuinfo | awk '{ print "+" $3 }' | tr -d
>> '\n' | cut -c 2- | bc > 6121.06
>> >
>> > Your mission: To work out what it's doing, why you'd be stupid
>> enough to > want to do it, and then how to do it better. It has to
>> be in shell, and it > has to handle decimals! :-)
>> 
>> Too easy. You just need to learn some more awk Mr Waugh :) You
>> don't even need to fork at all.
>> 
>> $ awk '{ if(/bogomips/){ SUM+=$3 } } END {print SUM}' /proc/cpuinfo

Jessica> ... on second thoughts. awk is better. I bow to your
Jessica> awk-lord-ness :)

At least use the pattern matching that's built into AWK:

awk '/bogomips/ { sum += $3 }
END {print sum}' /proc/cpuinfo


PeterC
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug