How to Addition and subtraction..using files

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Addition and subtraction..using files
# 15  
Old 09-12-2011
hi ahamed

sorry for the inconveniance

i am running the file from my desktop okay in that 2 file names

anish.txt contains value 10
kuamr.txt contains value 5
and this 2 file names alone stored in another 2 files example

/var/tmp/v1 contain anish.txt
/var/tmp/v2 contain kumar.txt
and i want the input 2 filenames need to read from another file.

and now i using the commad which you give

awk 'NR==FNR{a=$0;next} {b=$0; print a-b}' $(</var/tmp/v1) $(</var/tmp/v2)

# 16  
Old 09-12-2011
It is working for me. which is your shell? Hope you are running the command from where you have the anish.txt and kumar.txt files.

This User Gave Thanks to ahamed101 For This Post:
# 17  
Old 09-12-2011
Originally Posted by Corona688
Smilie Your requirement is that it be slow and inefficient?

Or are you writing large things in pure awk?

If the latter, you can incorporate this into part of a larger awk statement more easily:

awk 'BEGIN {
        getline VAR1 <"filename1"
        getline VAR2 <"filename2"
        printf("%d+%d=%d\n", VAR1, VAR2, VAR1+VAR2);

The total script is based on domain count in a large zone.

1. first get the domain names alone in a zone file using AWK

2. then removing the duplicates using AWK

3. then count the number of domains using AWK

4. then comparing 2 zone files and doing arithmetic calculations usinga AWK

now iam in final that slight confusions..thats why i am here i hope i get the answer here

---------- Post updated at 11:14 PM ---------- Previous update was at 11:11 PM ----------

Thanks alot man u made my day its woking like charm...i made some typho error so thanks a lot.
This User Gave Thanks to anishkumarv For This Post:
# 18  
Old 09-12-2011
If this is the case, Corona's solution is better since you can embed this with your remaining awk!

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Date Subtraction

Hello All, I am a newbie to unix shell scripting and need to write a script that displays the difference between two variables that stores date value. For example, F1=`ls -ltr file1* | tail -1 |tr -s ' ' |cut -d' ' -f6,7,8` F2=`ls -ltr file2* | tail -1 |tr -s ' ' |cut -d' ' -f6,7,8` F1... (3 Replies)
Discussion started by: priyaa2010
3 Replies

2. Shell Programming and Scripting

Need Help on date subtraction

I have dates as follows in a file 20121029135649 20121029135721 20121030091540 20121030093420 20121030094340 20121030095427 20121030095856 20121030100104 20121030100251 All these dates are in sorted order. I need to find out the difference between the dates as follows 2nd row... (6 Replies)
Discussion started by: meetsriharsha
6 Replies

3. Shell Programming and Scripting

Subtraction using arrays

Hello all . I have two arrays. ${ARRAY_MOUNT_POINT_CAPACITY} ${ARRAY_MOUNT_POINT_CAPACITY}. Whats the synatx of subtracting their values , placing them in variable V1 and then echoeing it ??? Ive tried expr and let me ./ difference: bad number (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

4. Shell Programming and Scripting

Splitting of files - Addition of Page Number in the Trailer

Hi, I need your help on the following Scenario : Consider a file has 650 records and I need to split this file into 4 files having a maximum of 200 records in each of them and also for the first splitted file it should get appended with Page 1 as a trailer( Similarly for the second file, Page... (4 Replies)
Discussion started by: Ravichander
4 Replies

5. Shell Programming and Scripting


Hi #!/bin/sh month=`date +%m` year=`date +%Y` echo $month a=02 # Retaining Data for Current and Previous Month lmonth=`expr $month - $a` if test "$lmonth" = "0" then lmonth=12 year=`expr $year - 1` fi echo $year echo $lmonth The output is (3 Replies)
Discussion started by: Abhayman
3 Replies

6. Shell Programming and Scripting

use of uninitialized value in subtraction

Hallo all i am trying to execute this script ............... But this is throwing the error...... use of uninitialized value in subtraction in at line 156 use of uninitialized value in subtraction in at line 157 use of uninitialized value in subtraction in at... (1 Reply)
Discussion started by: suvenduperl
1 Replies

7. Shell Programming and Scripting

Date subtraction

hi, i set up a script on my server to do a particular task once files from an external system are ftpd in the format compaq_20100110 (YYDDMM). Interestingly, the source of ftp is sending the files in the format e.g 20100109 i.e. previous date and for some reason this fails.kindly see my script... (2 Replies)
Discussion started by: bigtejus
2 Replies

8. Shell Programming and Scripting

subtraction in bash arrays

hi i am using bash shell to perform some subraction. here is what i have: i have a while loop and am using i as a counter. diff= `expr ${ARRAY1} - ${ARRAY2}` for example array1 has -0.7145 and array2 has -0.7041. when i try the above command, i get expr: non-numeric argument. any... (6 Replies)
Discussion started by: npatwardhan
6 Replies

9. Shell Programming and Scripting

awk subtraction

hi i have file 1 as follows: 6 7 8 9 10 i have file 2 as follows: 5 5 5 5 5 i want file 3 as follows: (4 Replies)
Discussion started by: npatwardhan
4 Replies

10. UNIX for Dummies Questions & Answers

subtraction from date

hi gurus! i realize that my question shows my stupidness, but i need your help! i have: s_date=`date +%m-%d-%Y_%I%p` variable and i need the same, but minus one hour.. what i made: s_date=time(`date +%m-%d-%Y_%I%p`) - 3600 but i'm getting: line 20: syntax error near... (4 Replies)
Discussion started by: MarGur
4 Replies
Login or Register to Ask a Question