Subtract two variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Subtract two variable
# 1  
Old 02-28-2013
Subtract two variable

plz help me in simple calculation.

Have to substract two variable (in Bytes) and change the output into MB.

Code:
A=`more /tmp/size_info_old.out |awk NR==3`
echo "$A" > /tmp/rav/A.out
B=`more /tmp/size_info.out |awk NR==3`
echo "$B" > /tmp/B.out
C=$(((B-A))/1024/1024)
 
echo "$C" /tmp/final_report

or any other simple way to do this

Thanks in Advance

Last edited by Franklin52; 02-28-2013 at 03:10 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 02-28-2013
try sth like this..


Code:
awk 'NR==3{A=$0}
	FNR==3 && NR > 3{B=$0}
	END{print (B-A)/(1024*1024)}' /tmp/size_info_old.out /tmp/size_info.out

This User Gave Thanks to pamu For This Post:
# 3  
Old 02-28-2013
Another way,
Code:
awk 'FNR==3 { x[f++]=$0 } END {print (x[1]-x[0])/(1024*1024)}' /tmp/size_info_old.out /tmp/size_info.out

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Subtract time in two line

INPUT: 16:45:51 10051 77845 16:45:51 10051 77845 16:46:52 10051 77846 16:46:53 10051 77846 Match the last PID then subtract second line time with first line. Please help me with any command or script. (3 Replies)
Discussion started by: vivekn
3 Replies

2. Shell Programming and Scripting

Match and subtract two fields

Not sure quite how to do this, but I am trying to use $1 of LCH.txt (exact match) to look for a match in $1 of genes.txt. If a match is found then in a new file match.txt $1 $2 ($4-$3) are copied. Example, the first record in LCH is PPT1 and that matches row 713, column 1 of genes.txt. ... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Add or Subtract the hours,minutes or seconds in the the time variable

Hello All, I am working on script where I need to add hours,minutes or seconds in the time.Time is not the current but it could be future time.I thought I can store that time in variable and add hours.minutes or second but I am not able to add that in the time that is stores in a variable. Time... (9 Replies)
Discussion started by: anuragpgtgerman
9 Replies

4. Shell Programming and Scripting

Script to subtract time stored in a variable

Hello, I am writing a script to find time difference between two timestamp stored in a variable. i have two variable t1=11:48:30 t2=13:13:48 how i can find the difference i.e t2-t1 in seconds. Please help (4 Replies)
Discussion started by: anand2308
4 Replies

5. Shell Programming and Scripting

Help need to subtract the data from 2 columns

space_used.lst /dev/vx/dsk/A06487-S01-c4e3s-ORACLE-dg/oradata01 505G 318G 175G 65% /dborafiles/nethealth21/PV/oradata01 /dev/vx/dsk/A06487-S01-c4e3s-ORACLE-dg/oradata02 505G 433G 67G 87% /dborafiles/nethealth21/PV/oradata02 /dev/vx/dsk/A06487-S01-c4e3s-ORACLE-dg/oradata03 507G 422G 79G 85%... (4 Replies)
Discussion started by: sathik
4 Replies

6. Shell Programming and Scripting

Script to subtract rows HELP

Dear All, Please help with a script which can accomplish the following: Input table: $1 $2 $3 Student1 1 50 Student2 56 75 Student3 77 100 Desired Output: $1 $2 $3 $4 Student1 1 50 Student2 56 75 6 Student3 77 ... (4 Replies)
Discussion started by: saint2006
4 Replies

7. Shell Programming and Scripting

how to subtract variables

i have var1=abc def var2=abc I want to do var1-var2 ie i want def how can i do it? Thanks please help (1 Reply)
Discussion started by: javaholics
1 Replies

8. Shell Programming and Scripting

Subtract days from a variable holding date

Hi, could someone help on this.. I have a date in variable procdate="05/30/2009" I would want to Subtract it with 3 or 4 (2 Replies)
Discussion started by: infernalhell
2 Replies

9. UNIX for Advanced & Expert Users

Subtract 2 months from the date

I have the script which appends month and year to the name of the file. Now every time when I append the month-year combination I have to subtract 2 months from the current date and then append it, since we are sending our vendor 2 months prior worth of data eveytime. #! /usr/bin/ksh ... (5 Replies)
Discussion started by: mahekr2000
5 Replies

10. Shell Programming and Scripting

Subtract Time

Hello, Im writing a script using the ksh shell. I have 2 variables in the script: CURRTIME PREVTIME Example, if CURRTIME=13:00, I want to somehow calculate what the time was an hour ago so that PREVTIME=12:00 Right now I have the following: CURRTIME=`date +%H:%M` How can I... (4 Replies)
Discussion started by: xadamz23
4 Replies
Login or Register to Ask a Question