The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using loop reading a file,retrieving data from data base. Sonu4lov Shell Programming and Scripting 1 01-19-2007 03:38 AM
Subtract 2 months from the date mahekr2000 UNIX for Advanced & Expert Users 5 07-23-2006 01:01 PM
Subtract Time xadamz23 Shell Programming and Scripting 4 12-04-2005 02:18 AM
Subtract two dates in different lines vanand420 UNIX for Dummies Questions & Answers 1 07-11-2005 02:40 AM
Subtract two date in unix vanand Shell Programming and Scripting 1 06-18-2005 08:19 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-28-2007
krishna_sicsr krishna_sicsr is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 25
Unhappy 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 (permalink)  
Old 03-28-2007
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
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 (permalink)  
Old 03-29-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398

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

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:06 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0