Sed help (for bash scripting)

OT: anything goes!

Moderator: Edi

Post Reply
User avatar
Pu-239
Sith Marauder
Posts: 4727
Joined: 2002-10-21 08:44am
Location: Fake Virginia

Sed help (for bash scripting)

Post by Pu-239 »

I'm trying to remove everything after the first number with sed in this sequence:
0.89 0.77 0.73 2/47 1601 (from /proc/loadavg) then turn it into a whole number for use in a script.

cat /proc/loadavg|sed s/?.??//2|sed s/?.??//2|sed s/*\/*// doesn't work.

And how do you multiply or round numbers in a shell script?

ah.....the path to happiness is revision of dreams and not fulfillment... -SWPIGWANG
Sufficient Googling is indistinguishable from knowledge -somebody
Anything worth the cost of a missile, which can be located on the battlefield, will be shot at with missiles. If the US military is involved, then things, which are not worth the cost if a missile will also be shot at with missiles. -Sea Skimmer


George Bush makes freedom sound like a giant robot that breaks down a lot. -Darth Raptor
User avatar
Darth Wong
Sith Lord
Sith Lord
Posts: 70028
Joined: 2002-07-03 12:25am
Location: Toronto, Canada
Contact:

Re: Sed help (for bash scripting)

Post by Darth Wong »

Pu-239 wrote:I'm trying to remove everything after the first number with sed in this sequence:
0.89 0.77 0.73 2/47 1601 (from /proc/loadavg) then turn it into a whole number for use in a script.

cat /proc/loadavg|sed s/?.??//2|sed s/?.??//2|sed s/*\/*// doesn't work.

And how do you multiply or round numbers in a shell script?
Try using awk instead of sed.
Image
"It's not evil for God to do it. Or for someone to do it at God's command."- Jonathan Boyd on baby-killing

"you guys are fascinated with the use of those "rules of logic" to the extent that you don't really want to discussus anything."- GC

"I do not believe Russian Roulette is a stupid act" - Embracer of Darkness

"Viagra commercials appear to save lives" - tharkûn on US health care.

http://www.stardestroyer.net/Mike/RantMode/Blurbs.html
User avatar
Pu-239
Sith Marauder
Posts: 4727
Joined: 2002-10-21 08:44am
Location: Fake Virginia

Post by Pu-239 »

ok, I'll try tommorrow.

ah.....the path to happiness is revision of dreams and not fulfillment... -SWPIGWANG
Sufficient Googling is indistinguishable from knowledge -somebody
Anything worth the cost of a missile, which can be located on the battlefield, will be shot at with missiles. If the US military is involved, then things, which are not worth the cost if a missile will also be shot at with missiles. -Sea Skimmer


George Bush makes freedom sound like a giant robot that breaks down a lot. -Darth Raptor
User avatar
BoredShirtless
BANNED
Posts: 3107
Joined: 2003-02-26 10:57am
Location: Stuttgart, Germany

Re: Sed help (for bash scripting)

Post by BoredShirtless »

Pu-239 wrote:I'm trying to remove everything after the first number with sed in this sequence:
0.89 0.77 0.73 2/47 1601 (from /proc/loadavg) then turn it into a whole number for use in a script.

cat /proc/loadavg|sed s/?.??//2|sed s/?.??//2|sed s/*\/*// doesn't work.

And how do you multiply or round numbers in a shell script?
I'd like to answer your question, but I don't want to deprive you of doing your own homework :P
Crazy_Vasey
Jedi Council Member
Posts: 1571
Joined: 2002-07-13 12:56pm

Post by Crazy_Vasey »

It would be a great deal easier to do that in python.
Post Reply