Geeks Talk

Prepare for your Next Interview




Math Calculations - Unix Shell

This is a discussion on Math Calculations - Unix Shell within the Unix/Linux forums, part of the Operating Systems category; Can someone tell me how to do the following inside a unix script? I have a file and can do a wc -l on it....say the count is 123 ...


Go Back   Geeks Talk > Operating Systems > Unix/Linux

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-21-2008
Junior Member
 
Join Date: May 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
basehit524 is on a distinguished road
Math Calculations - Unix Shell

Can someone tell me how to do the following inside a unix script?

I have a file and can do a wc -l on it....say the count is 123 lines.

#wcl /tmp/file
>123

I would then like to divide this number by 2 to get a decimal number.

# wcl /tmp/file| `expr /tmp/file /2`

Can't find the right expr combo.

Any idea how to accomplish this?

Thx.
Kurt
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-24-2008
Junior Member
 
Join Date: Nov 2007
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Sanpri is on a distinguished road
Thumbs up Re: Math Calculations - Unix Shell

Hi,

you can first store the o/p of wc -l value in a variable.

say a = wc -l /tmp/file.

then b=`expr $a/2`

Thanks.
Reply With Quote
Sponsored Links
Reply

  Geeks Talk > Operating Systems > Unix/Linux


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
How to Submit a concurrent program from a Unix Shell Script sunil_sadige Oracle Apps 1 02-07-2008 08:32 AM
Math Matrix in C++ The Professional C and C++ 0 12-04-2007 03:36 AM
Aston Shell is a powerful, fast, stable and flexible shell replacement application. JobHelper Geeks Lounge 0 09-21-2007 03:11 AM
About Shell Layer Management in UNIX nancyphilips Unix/Linux 2 12-14-2006 07:51 AM
Difference in UNIX Shell scott Unix/Linux 2 07-23-2006 11:40 AM


All times are GMT -4. The time now is 04:15 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved