Compare and calculate two variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare and calculate two variables
# 8  
Old 11-27-2013
Use a for loop:
Code:
        BEGIN {
                split ( V1, A1 )
                n = split ( V2, A2 )
                for ( i = 1; i <= n; i++ )
                        printf "%.5f ", A1[i] - A2[i]
                printf "\n"
        }
'

# 9  
Old 11-27-2013
Quote:
Originally Posted by Yoda
Use a for loop:
Code:
        BEGIN {
                split ( V1, A1 )
                n = split ( V2, A2 )
                for ( i = 1; i <= n; i++ )
                        printf "%.5f ", A1[i] - A2[i]
                printf "\n"
        }
'

Excellent Yoda, worked perfectly, another question, have an idea for you to replace the results of the numerical data in a different text file where are the previous values ​​replace them with the result new values ​​and add where there is an increase in the + symbol and where has decreased the symbol -
The solution I found is to separate the numerical data file
example
Data 1
one value 29.90003
two value 50.43334
grep-o [0-9]. * file (get only numeric and.)
Need only replace the new values ​​without touching the data reference
Data 1
one value -23.00000
two value +51.43334
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Compare two variables and print the difference

compare two variables and print the difference i have two variables X1=rac1,rac2 Y1=rac2,rac3 output=rac1,rac3 Use code tags to wrap code fragments or data samples. (1 Reply)
Discussion started by: jhonnyrip
1 Replies

2. Shell Programming and Scripting

Compare two variables and print the difference

Hi PRIM_SEQ=`some sql code` and output of PRIM_SEQ is like below 120 130 STB_SEQ=`some sql code` and output of STB_SEQ is like below 115 110 i need to compare this two variables output ( decimal numbers) 1) What I want to do is to compare every number in the PRIM_SEQ with... (8 Replies)
Discussion started by: amar1208
8 Replies

3. Shell Programming and Scripting

read line by line and calculate the co-presence of variables

Hey guyz, I have a table which shows the presence or absence of my variables (A,B,C,...) in my observations (1,2,3,...) * A B C ... 1 1 0 1 2 1 1 0 3 1 0 0 ... I want to calculate the co-presence of my variables. to have a table shows the pairwise presence of the variables (have... (1 Reply)
Discussion started by: @man
1 Replies

4. Shell Programming and Scripting

How to compare floating variables , integer value expected?

I am running some commands and I am trying to get an output into a variable. I am having problem when I try to put that value in while loop, it says integer value expected. What's the best way to accomplish this remaining=$(symclone -sid XXX -f Clone_test query | grep MB | awk '{print... (1 Reply)
Discussion started by: rajsan
1 Replies

5. Shell Programming and Scripting

using awk compare two variables in bash

ok this is probably going to turn out to be something really stupid but i've tried to use the following command in a script but the output is just a blank screen and i have to use Ctrl c to exit it. awk 'BEGIN {printf "%.2f\n", '${bashArray}'>='$Variable' {print '${bashArray}'}}' the command... (2 Replies)
Discussion started by: zagreus360
2 Replies

6. Shell Programming and Scripting

HELP: compare floating point variables??

Hi All, I got this script that pulls the Amps value from our RPC's , I basiclly want to compare the valued with a "limit" value -- if the numbers match or are greater than the definded value ...do something. My problem is I cant seem to figure out how to compare floating points... here is... (1 Reply)
Discussion started by: zeekblack
1 Replies

7. Shell Programming and Scripting

Awk - Compare fields and increment variables

Hi, My first post to this group... I have a need to to parse a source file which is a capture from a network analyser. I have two fields that need to be checked: - Field 7 represents the packet length (an integer), and Field 4 represents a network address (e.g. 192.168.25.3) - The... (10 Replies)
Discussion started by: mv652
10 Replies

8. Shell Programming and Scripting

Compare String Variables for Greater or Less Than?

Is there any way to compare two strings for a greater or less than condition? For example, StringA is "apple" and StringB is "bonnet" and StringC is "captain". Can I only test for equal/not-equal, or is there a way to find out whether StringA is less than StringB, and StringC is greater than... (6 Replies)
Discussion started by: OPTIMUS_prime
6 Replies

9. Shell Programming and Scripting

Compare two variables

Hi guys, How do I compare two variables using diff? The way I'm thinking: #!/bin/sh a=cat asdf.x | wc -l b=cat asdf.y |cut -d',' -f5 |grep -v '^$' |wc -l diff $a $b How to rewrite the above sciprt using only one line in command prompt? (2 Replies)
Discussion started by: onthetopo
2 Replies

10. Shell Programming and Scripting

How do I compare mixed variables?

Searched all over can't figure out how to compare variables of alpha and numeric characters. Example a script that ask user to enter a password and then ask to repeat the password. (6 Replies)
Discussion started by: monx
6 Replies
Login or Register to Ask a Question