How to subtract data of two different file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to subtract data of two different file
# 1  
Old 03-28-2007
Data How to subtract data of two different file

I want to access of two different file.

cat in_file | awk -F: '{
in_total += $1 * 86400 + $2 * 3600 + $3 * 60 + $4
} END {printf "%d\n",in_total} '


cat out_file | awk -F: '{
out_total += $1 * 86400 + $2 * 3600 + $3 * 60 + $4
} END {printf "%d\n",out_total} '


I want to sub out_total from in_total
# 2  
Old 03-28-2007
Just include that in a shell script

Code:
#!/bin/ksh
in_total=`cat in_file | awk -F: '{in_total += $1 * 86400 + $2 * 3600 + $3 * 60 + $4} END {printf "%d\n",in_total} '`
out_total=`cat out_file | awk -F: '{out_total += $1 * 86400 + $2 * 3600 + $3 * 60 + $4} END {printf "%d\n",out_total} '`
(( total = in_total - out_total ))
print "Total is " $total

# 3  
Old 03-29-2007
Code:
awk -F: ' FILENAME == "in_file" {
in_total += $1 * 86400 + $2 * 3600 + $3 * 60 + $4
} 
FILENAME == "out_file" {
out_total += $1 * 86400 + $2 * 3600 + $3 * 60 + $4
}
END {printf "%d\n",in_total - out_total } ' in_file out_file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Subtract a file's modification date with current date

SunOS -s 5.10 Generic_147440-04 sun4u sparc SUNW,SPARC-Enterprise Hi, In a folder, there are files. I have a script which reads the current date and subtract the modification date of each file. How do I achieve this? Regards, Joe (2 Replies)
Discussion started by: roshanbi
2 Replies

2. Shell Programming and Scripting

Help to subtract columns from 2 files and output to new file

Hi, I have 2 files in below formats File1_Stored.txt ABC:100, 83 ABC:84, 53 ABC:14, 1222And File2_Stored.txt ABC:100 , 83 ABC:84 , 1553 ABC:524 , 2626I am trying to get the 3rd file in below format. So, whenever difference is 0 it shouldn't appear but if the difference is not 0 then... (2 Replies)
Discussion started by: Abhayman
2 Replies

3. Shell Programming and Scripting

awk to subtract from values in file

data.txt: 0,mq_conn_open_error,1444665949,734,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62022,0,733--734 0,mq_conn_open_error,1444666249,734,/PROD/G/cicsitlp/sys/unikixmain.log,64K,mq_conn_open_error,62022,0,734--734... (7 Replies)
Discussion started by: SkySmart
7 Replies

4. Shell Programming and Scripting

Replace data of a file with data from another file using shell scripting.

Dears, I'm new to shell scripting and i was wondering if you can help me with following matter. I have a file containing 400,000 records. The file contains two columns like: 00611291,0270404000005453 25262597,1580401000016155 25779812,1700403000001786 00388934,1200408000000880... (1 Reply)
Discussion started by: paniklas
1 Replies

5. Shell Programming and Scripting

Extract header data from one file and combine it with data from another file

Hi, Great minds, I have some files, in fact header files, of CTD profiler, I tried a lot C programming, could not get output as I was expected, because my programming skills are very poor, finally, joined unix forum with the hope that, I may get what I want, from you people, Here I have attached... (17 Replies)
Discussion started by: nex_asp
17 Replies

6. Shell Programming and Scripting

Subtract 2 date columns in .csv file and get output as number of days

Hi, I have one .csv file. I have 2 date columns present in file, column 2 and column 3. I need to calculate how many days exist between 2 dates. I am trying to subtract date column 2 from date column 3. Eg: my file look likes s.no, Start_date,End_Date 1, 7/29/2012,10/27/2012 2,... (9 Replies)
Discussion started by: Dimple
9 Replies

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

8. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

9. Shell Programming and Scripting

Need help to subtract columns from 2 files and output to new file

Hi, I need some help figuring this out, I think it can be done using awk but I don't know how. So, I want to take two input files, subtract some columns with each other and then output to a new results file. InFile1.txt AAA 100 200 BBB CCC 300 400 DDD InFile2.txt AAA 50 60 BBB CCC 70... (7 Replies)
Discussion started by: MrTrigger
7 Replies

10. Shell Programming and Scripting

Find and replace data in text file with data in same file

OK I will do my best to explain what I need help with. I am trying to format an ldif file so I can import it into Oracle oid. I need the file to look like this example. Keep in mind there are 3000 of these in the file. changetype: modify replace: userpassword dn:... (0 Replies)
Discussion started by: timothyha22
0 Replies
Login or Register to Ask a Question