how to subtract variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to subtract variables
# 1  
Old 08-04-2010
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
# 2  
Old 08-04-2010
Bash and (newer) KSH:
Code:
$ var1="abc def"
$ var2=abc
$ echo ${var1/$var2/}
def

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to recalculate (subtract) before a reformat.

We are having to read a number of files from an outside source and have been given a layout that looks like this LNPDTO 383 8 DATE Comment LNACIN 391 14 S2 Comment LNDEFI 405 14 S2 Comment LNYTDI 419 14 S2 ... (2 Replies)
Discussion started by: wbport
2 Replies

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

3. Solaris

Subtract 2 days from timestamp

Hi, I am running on Solaris 11.3. I have a timestamp in this format date +%Y%m%d%H%M . I found some forums saying to use date --d however that didn't work. Is there a way how I can subtract days from timestamp in that format? Thanks (12 Replies)
Discussion started by: nms
12 Replies

4. UNIX for Dummies Questions & Answers

Subtract minutes from date

Hi, I am reading a particular date from a file using below command WFLWDATE=$(sed '2q;d' FileA.prm) The echo command outputs the correct date in variable WFLWDATE Now I want to subtract 5 minutes from this variable. I am on AIX and unable to get anything working as expected. Can you... (1 Reply)
Discussion started by: vrupatel
1 Replies

5. Shell Programming and Scripting

Subtract two variable

plz help me in simple calculation. Have to substract two variable (in Bytes) and change the output into MB. 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"... (2 Replies)
Discussion started by: netdbaind
2 Replies

6. Shell Programming and Scripting

How to subtract a number from all columns?

Hi, I want to subtract a number from all columns except the first column. I have a number of files each having different columns around 60/70. How to do that in awk or any other command? Thanks Input Col 1 Col 2 Col3 - - - - Col55 1 .0123 .098 - - - 0.6728 2 - -... (3 Replies)
Discussion started by: Surabhi_so_mh
3 Replies

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

8. Shell Programming and Scripting

Subtract field values

I've got a long logfile of the form network1:123:45:6789:01:234:56 network2:12:34:556:778:900:12 network3:... I've got a similar logfile from a week later with different values for each of the fields eg network1:130:50:6800:10:334:66 network2:18:40:600:800:999:20 network3:... ... (5 Replies)
Discussion started by: Yorkie99
5 Replies

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

10. UNIX for Dummies Questions & Answers

Subtract two dates in different lines

Hi Friends :) I have a long file having fields in the form : Field1 yy/mm/dd hh:mm:ss Duration(Sec) line 1) 123123 05/11/30 12:12:56 145 line 2) 145235 05/11/30 12:15:15 30 line 3) 145264 05/11/30 13:14:56 178 . . I want to... (1 Reply)
Discussion started by: vanand420
1 Replies
Login or Register to Ask a Question