Problem in algebraic substraction


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in algebraic substraction
# 1  
Old 04-25-2012
Error Problem in algebraic substraction

my code is like this


Code:
count=`cat /filecount.txt | tail -1 |head -1| awk '{print $1}'`  ###file is having value 264  ####

echo "actual count = $count"

exact_count=`expr $value \* 24`

echo "exact_count= $exact_count"

diff=`expr "$exact_count" - "$count"`

a= exact_count - count

echo " value is &a"
echo "$diff"

but it is showing following error




Code:
actual count = 264
exact_count= 264
expr: An integer value was expected.

temp[55]: exact_count:  not found.
 value is &a

temp[55]: exact_count:  not found.
 value is &a


Last edited by sagar_1986; 04-25-2012 at 09:35 AM..
# 2  
Old 04-25-2012
Unless I'm being daft, you don't appear to have specified what $value is, so the command is trying to "Multiply by 24" rather than "$value multiplied by 24"



Robin
Liverpool/Blackburn
UK
# 3  
Old 04-25-2012
dear rbatte1

i am very new to UNIX i am giving full code.the filecount.txt is attached


Code:
echo -n "ENTER VALUE BETWEEN 01-31 "
read value
count=`cat /filecount.txt | tail -1 |head -1| awk '{print $1}'`  ###file is having value 264  ####
echo "actual count = $count"
exact_count=`expr $value \* 24`
echo "exact_count= $exact_count"
diff=`expr "$exact_count" - "$count"`
a= exact_count - count
echo " value is &a"
echo "$diff"

# 4  
Old 04-25-2012
error massage is


Code:
actual count = 264
exact_count= 264
expr: An integer value was expected.

temp[55]: exact_count:  not found.
 value is &a

temp[55]: exact_count:  not found.
 value is &a

# 5  
Old 04-25-2012
One error is due to value with leading space entered by user. Also I made few correction in your script.
Code:
echo -n "ENTER VALUE BETWEEN 01-31 "
read value
count=`tail -1 filecount.txt | tr -d " "`  ###file is having value 264  ####
echo "actual count = $count"
exact_count=`expr $value \* 24`
echo "exact_count= $exact_count"
diff=`expr "$exact_count" - "$count"`
a=`expr "$exact_count" - "$count"`
echo " value is $a"
echo "$diff"

This User Gave Thanks to 47shailesh For This Post:
# 6  
Old 04-26-2012
thanks 47shailesh

it works perfect.....
# 7  
Old 04-26-2012
Hi sagar,

Did you understand the actual problem with your original script that is pointed out by rbatte1?

OK
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substraction of matching lines from a file.

I have 2 files: file1.txt contains /html/mybook/Charts/143712/reptiles.pdf /html/mybook/Charts/198459/spices.pdf /html/mybook/Charts/198459/fresh_nuts.pdf /html/mybook/Charts/123457/dome_anim.pdf /html/mybook/Charts/123457/vegetables.pdf /html/content/3DInteractive/174091/CSPSGGB.html ... (6 Replies)
Discussion started by: Jojan Paul
6 Replies

2. Shell Programming and Scripting

awk - sed / reading from a data file and doing algebraic operations

Hi everyone, I am trying to write a bash script which reads a data file and does some algebraic operations. here is the structure of data.xml file that I have; 1 <data> 2 . 3 . 4 . 5 </data> 6 <data> 7 . 8 . 9 . 10</data> etc. Each data block contains same number of lines (say... (4 Replies)
Discussion started by: hayreter
4 Replies

3. Shell Programming and Scripting

Substraction in shell scripting

Hello friends, I am new on linux, i am facing issues on below script. #!/bin/sh current=1355147377 echo $current last_modified=1354537347 echo $last_modified DIFF='expr ($current - $last_modified)' echo $DIFF Please view this code tag video for how to use code tags when posting... (8 Replies)
Discussion started by: sanjay833i
8 Replies

4. Shell Programming and Scripting

Try solver System of linear algebraic equations in Shell Bash

I want to try solving system of linear algebraic equations in Shell bash but i have any problems Value input is matrix and I dont know how to input matrix in Shell because that is dont support 2-dimensional array Please help me. Thank you so much (3 Replies)
Discussion started by: newbieseos
3 Replies

5. Shell Programming and Scripting

problem in algebraic expression

count=`cat /filecount.txt | tail -1 |head -1| awk '{print $1}'` exact_count=`expr $value \* 24` i want to subtract a="$exact_count" - "$count" but its not taking o/p of "count" as number $a is wrong answer hence not getting proper output. plz help me out :confused: Please use... (3 Replies)
Discussion started by: sagar_1986
3 Replies

6. Shell Programming and Scripting

date substraction

hello i have obtained the current date .. current_date=date "+%m/%d%y" and i have another date ,stored in my log file which i have already retrieved. i want to store the subtraction in a varible called diff. diff=log_date - currentdate ex: log_date=01/28/11 current_date=... (3 Replies)
Discussion started by: urfrnddpk
3 Replies

7. AIX

user login problem & Files listing problem.

1) when user login to the server the session got colosed. How will resolve? 2) While firing the command ls -l we are not able to see the any files in the director. but over all view the file system using the command df -g it is showing 91% used. what will be the problem? Thanks in advance. (1 Reply)
Discussion started by: pernasivam
1 Replies

8. Solaris

Substraction in bash

Hi all, I have in one script something like this: FIRSTOCC=`grep -n ORA- alert_bill2.log |tail -"$ROWS"|head -1|cut -d: -f1` TOTAL=`more alert*|wc -l` DIFFERENCE=`$TOTAL-$FIRSTOCC` echo Total lines in alert_bill = $TOTAL echo $DIFFERENCE How do I make this substraction work? Thk (2 Replies)
Discussion started by: mclaudiu
2 Replies

9. UNIX for Dummies Questions & Answers

Date Substraction

In Unix script, how to get a "date - 1" ie, yesterday? (4 Replies)
Discussion started by: AC
4 Replies
Login or Register to Ask a Question