problem in algebraic expression


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting problem in algebraic expression
# 1  
Old 04-25-2012
problem in algebraic expression

Code:
count=`cat /filecount.txt | tail -1 |head -1| awk '{print $1}'`

exact_count=`expr $value \* 24`

i want to subtract
Code:
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

Smilie

Moderator's Comments:
Mod Comment Please use [code] tags. Video tutorial on how to use them
# 2  
Old 04-25-2012
In ksh:
Code:
# value=4                        
# (( exact_count = value * 24 )) 
# echo $exact_count
96
# count=10
# (( a = exact_count - count  ))    
# echo $a
86

# 3  
Old 04-25-2012
Try:
Code:
a=$(( exact_count - count ))

# 4  
Old 04-25-2012
Quote:
Originally Posted by Klashxx
In ksh:
Code:
# value=4                        
# (( exact_count = value * 24 )) 
# echo $exact_count
96
# count=10
# (( a = exact_count - count  ))    
# echo $a
86

its not working

i think there is problem in command
Code:
count=`cat /home/bsnl/sagar/filecount.txt | tail -1 |head -1| awk '{print $1}'`

its not taking o/p as number plz suggest some thing

---------- Post updated at 04:47 AM ---------- Previous update was at 04:46 AM ----------

Quote:
Originally Posted by Scrutinizer
Try:
Code:
a=$(( exact_count - count ))


ts not working

i think there is problem in command

Code:
count=`cat /home/bsnl/sagar/filecount.txt | tail -1 |head -1| awk '{print $1}'`

its not taking o/p of this as "number"

hence not working

o/p of script is like this

Quote:
actual count = 528
exact_count= 528
temp[52]: 528: not found.
temp[55]: exact_count: not found.
value is &a

Last edited by sagar_1986; 04-25-2012 at 07:16 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

Problem in algebraic substraction

my code is like this 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 ... (8 Replies)
Discussion started by: sagar_1986
8 Replies

4. Shell Programming and Scripting

Regular Expression problem

I have two input files (given below) and to compare each line of the File1 with each line of File2 starts with '>sample1'. If a match occurs and that matched line in the File2 contains another line or sequence of lines starting with "Chr" they have to be displayed in output file with that sample.... (8 Replies)
Discussion started by: hravisankar
8 Replies

5. Shell Programming and Scripting

Reading expression problem

I want to read a file -line by line which consists of the following statements Chr18:4000-4010 Chr20:4020-4030 Chr15:8000-8050 Pls. give a expression to read the line like this from a file Chr18:4000-4010 the given two replies reading like that Chr18:-10 but it is important to... (2 Replies)
Discussion started by: hravisankar
2 Replies

6. Shell Programming and Scripting

Problem with regular expression

Witam, mam oto taki ciąg znaków: 8275610268 + 9012383215 =niepotrzebnytextPotrzebuję w bash'u wyciągnąć obie liczby (mają taką samą liczbę cyfr), zapisać je do osobnych zmiennych, ale coś nie idzie, kombinowałem z grepem, ale nie potrafię skleić tego wyrażenia regularnego, no i potem przypisać do... (7 Replies)
Discussion started by: menda90
7 Replies

7. Shell Programming and Scripting

Problem with a regular expression

Hello! I'm working with AWK, and i have this code: /<LOOP_TIME>/,/<\/LOOP_TIME>/ I want that match every everything between <LOOP_TIME> and </LOOP_TIME>, but not if the line have a "#" before the tags. Someone can help me? Thanks! (6 Replies)
Discussion started by: claw82
6 Replies

8. UNIX for Dummies Questions & Answers

Regular Expression Problem

this is how my xyz.log file loooks like :- info ( 816): CORE1116: Sun ONE Web Server 6.1SP5 B08/17/2005 22:09 info ( 817): CORE5076: Using from info ( 817): WEB0100: Loading web module in virtual server at info ( 817): WEB0100: Loading web module in virtual server at perl... (12 Replies)
Discussion started by: chris1234
12 Replies

9. Shell Programming and Scripting

Regular Expression problem

Hi guys I've been trying to write a regular expression. If I'm tryin to validate a sequence of characters as follows... AB1-232-623482-743 43/3 where a) any character after the "AB" can be any alphanumeric character b) the " 43/3" part is optional is there a quick neat way for me... (5 Replies)
Discussion started by: djkane
5 Replies

10. UNIX for Dummies Questions & Answers

Regular Expression Problem

Display all of the lines in a file that contain "Raspberry" followed later in the line by the letter "a" I tried: grep Raspberry*a filename that didn't work Anyone know a solution? (1 Reply)
Discussion started by: netmaster
1 Replies
Login or Register to Ask a Question