Subtraction while reading a variable value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Subtraction while reading a variable value
# 8  
Old 11-30-2011
Thanks Bala any way via Shell?
# 9  
Old 11-30-2011
Code:
# s=0;while read x;do s=$(($s + $x));done < file.txt;echo $((8725 - $s))
287

This User Gave Thanks to balajesuri For This Post:
# 10  
Old 12-01-2011
in ur code replace as

Code:
state3=`expr $state3 - $ct`

This User Gave Thanks to siva shankar For This Post:
# 11  
Old 12-04-2011
Thanks a ton Bala and Siva..appreciate your help on this Smilie
# 12  
Old 12-04-2011
An awk solution...

Code:
awk '{b+=$1}END{print a-b}' a=8725 input_file

--ahamed
This User Gave Thanks to ahamed101 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem reading into Variable using KSH

hi all, i create 1 file.txt and inside it contain : file1 file2 file3 file 4 then output that i want in my script: $1=file1 $2=file2 $3=file3 $4=file4 but,when write in ksh script with: while read folder set - $( echo ${folder} ) i=1 while (($i <= $#)) do ... (2 Replies)
Discussion started by: proghack
2 Replies

2. Shell Programming and Scripting

Reading a variable in csh

I have a simple script that sets a value and reads the value in csh: set -x set a = 10 echo $a The output of the script does not show the value of a + set a = 10 + echo any help would be great. (4 Replies)
Discussion started by: pt14
4 Replies

3. Shell Programming and Scripting

reading variable value from a file

Hello, I need to read a variable value from script. Below is the scenario I am reading a value from an external file say a.txt a.txt: Jan Feb Mar I need the corresponding value of the months in in numerics such as Jan -->1, Feb-->2 etc. I have this mapping in another file... (1 Reply)
Discussion started by: aixjadoo
1 Replies

4. UNIX for Dummies Questions & Answers

Reading a variable from file

Hi, I have a situation where I need to read a variable from another file. But the problem is that the variable in the other file is starting with $. E.g. file1: $var1=out temp_ss.sh: . file1 echo "Print : $var1" It works fine if the file1 is having var1=out (note that it is... (6 Replies)
Discussion started by: shash
6 Replies

5. UNIX for Dummies Questions & Answers

assingn a variable a filename and then reading it in

Im trying to set a filename to a variable and then read the file in using the variable but im getting a syntax error. any ideas? #!/bin/bash function scanFile() { while read $1 do echo $filename done } file1=report.log scanFile() $file1 (3 Replies)
Discussion started by: magnia
3 Replies

6. Shell Programming and Scripting

Reading variable from file variable values

Hi, Here is the output of lpstat. I would like to read value of Queue which is(abxxxxb1)and status that is DOWN in first line. i dont care what is in second line. any one can help me.thanks Queue Dev Status Job Files User PP % Blks Cp Rnk ------- ----- ---------... (5 Replies)
Discussion started by: sagii
5 Replies

7. UNIX for Dummies Questions & Answers

reading more than one variable into a for loop

Hi, I have a file (details.txt) with 3 rows of variables ie... name postcode age john D fr25dd 25 mark W ab122aa 22 phil C cd343bb 33 What I want to do is read down the list with a loop and add each field into a one line piece of text... So I have a file (test1) which reads;... (3 Replies)
Discussion started by: starsky
3 Replies

8. Shell Programming and Scripting

reading ~/.bashrc variable

1) I've added a variable called IMPORT_HOME to my ~/.bashrc file: IMPORT_HOME=/import:$IMPORT_HOME 2) I sourced the bashrc file: source ~/.bashrc 3) In my bash script, i tried to echo out the IMPORT_HOME variable but it doesnt print out '/import/, only whitespace: #!/bin/bash echo... (2 Replies)
Discussion started by: nuGz
2 Replies

9. UNIX for Advanced & Expert Users

Urgent-reading a variable value

Hi, I have a text file in which , I have contents like t1=abc t2=xyz t3=awe ...... I am able to read contents of these variables in a script by . /temp.txt echo $t1 Now, what my requirement is something like this a="t" i=1 echo $a$i --->this is displaying t1 (3 Replies)
Discussion started by: kaaakrishna
3 Replies

10. Shell Programming and Scripting

perl not reading my variable

I'm trying to make changes in a file using the following bash script: #!/bin/bash MYHOME=`echo $HOME` README=$MYHOME"/environment" IAM=`whoami` CHANGEPATHLIST="TALOG TACONFIG TAINFO TAWORK TMPSPACE" for var in $CHANGEPATHLIST do perl -pi -e 's/sacuser1/$IAM/ if m/$var/' $README... (3 Replies)
Discussion started by: yoonixq4u
3 Replies
Login or Register to Ask a Question