error- multiplying negative decimal values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting error- multiplying negative decimal values
# 1  
Old 09-07-2011
Error error- multiplying negative decimal values

Code:
a=10.02
pattern=-11.01
b=$(echo | awk '{ print $a*$pattern}')
echo $b

its not working even
ALso tried `expr $a \* $pattern`

No LUCK

Last edited by radoulov; 09-07-2011 at 06:51 AM.. Reason: Code tags!
# 2  
Old 09-07-2011
Code:
 
b=$(echo | awk '{ print $a*$pattern}')

Code:
 
b=$(echo "$a * $pattern" | bc)

# 3  
Old 09-07-2011
Quote:
Originally Posted by itkamaraj
Code:
 
b=$(echo | awk '{ print $a*$pattern}')

Code:
 
b=$(echo "$a * $pattern" | bc)

bc is not register on my m/c,
any other clue?
# 4  
Old 09-07-2011
Code:
$ a=10.02
$ pattern=-11.01
$ echo $pattern + $a | bc
-.99
$ echo $pattern \* $a | bc
-110.33
$

---------- Post updated at 03:17 PM ---------- Previous update was at 03:15 PM ----------

Code:
$ echo "10.02 -11.01" | nawk '{b=$1*$2; {print b}}'
-110.32

This User Gave Thanks to jayan_jay For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Negative decimal to binary

Is there a fast way to convert a negative decimal value into a signed binary number in bash script ? I've looked a lot on internet but I saw nothing... (For exemple : -1 become 11111111.) (9 Replies)
Discussion started by: Zedki
9 Replies

2. Shell Programming and Scripting

How to sum the value with negative values?

Hi Gurus, I have requirement need to sum the value, the logic is if the value is negative then time -1, I tried below two ways. one is failed, another one doesn't work. awk -F"," '{if($8< 0 $8*-1 else $8) sum+=$8}{print sum, $8} END{printf("%.2f\n",sum)}' awk -F","... (4 Replies)
Discussion started by: ken6503
4 Replies

3. Shell Programming and Scripting

Conavert negative values to Zeros

Can anyone please assist me? Please find the attached input and output file for ur reference. a)Incase if i get negative value (ex:-000100) in the 11th column then i have to convert the value to 0000000(7 zeros-length is 7) and then print the entire record. b)Incase if there is no... (2 Replies)
Discussion started by: vinus
2 Replies

4. Shell Programming and Scripting

Awk+colpos+negative if for 20 values

Hi All, i have 20 Obligors when ever i dont find all of them on particular row/line from each in put i need to print it in different file. using below command but it is not working please help at earliest. Steps: set -A FILENAME $( cat... (10 Replies)
Discussion started by: rajubollas
10 Replies

5. Shell Programming and Scripting

Help needed with multiplying two values of two columns in a file

Hi, I am trying to multiply column#1 with column#2 using a shell script. How can I make a for-loop script using 1st column as "i" and the second column as "j" from the following file? Please feel free to share any alternative ways to multiplying column#1 with column#2. .06 5.0000 .49 ... (6 Replies)
Discussion started by: momin
6 Replies

6. Shell Programming and Scripting

replacing negative values in a column with zero

Hi, i need help on replacing negative values in a column with 0. any quick fix on this? thanks much. for instance, input: 1 2.3 -0.4 -25 12 13 45 -12 desired output 1 2.3 0 0 12 13 45 (4 Replies)
Discussion started by: ida1215
4 Replies

7. Shell Programming and Scripting

Converting string to negative decimal value

I need code for converting a string to a negative decimal value. For ex, i have the value in the form of a string (5489.95-) i need to convert it into decimal value (-5489.95) while getting output using printf command. i know how to get as a string a="5489.95-" printf "%10s"$a >>xyz.dat ... (5 Replies)
Discussion started by: angie1234
5 Replies

8. Shell Programming and Scripting

multiplying values from two text files

Im very new to programming. But I would like to write a script which extracts and multiply values from 2 txt and output as a new file. Can someone please teach me how to write it? Thank you so much for example File A File B 1 34 1 2 2 13 2 2 3 8 3 3 File C output 1 68 2... (2 Replies)
Discussion started by: crunchichichi
2 Replies

9. Shell Programming and Scripting

Sorting positive and negative values

Hello, I have a list like this : 1 2 -4 0 -3 -7 5 6 etc. Is there a way to remove all the positive values and print only the negative values, without using grep, sed or awk? Thanks, Prasanna (4 Replies)
Discussion started by: prasanna1157
4 Replies

10. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies
Login or Register to Ask a Question