-
Junior Member
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
-
Junior Member
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.
-
Junior Member
Re: Math Calculations - Unix Shell
ur approch is right but u need to change some thing
as wc -l does not only returns file rows it also return file name so that name can not be divided
so use cut to remove that file name
also make sure in expr there should be space around arithmetic operator
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules