The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
How To Calculate krishna_sicsr Shell Programming and Scripting 3 03-21-2009 01:49 PM
calculate the space za_7565 Shell Programming and Scripting 8 05-04-2008 07:22 AM
How to calculate with awk whatisthis Shell Programming and Scripting 4 11-09-2005 12:39 PM
calculate size of some files big123456 Shell Programming and Scripting 11 07-22-2005 05:07 PM
How to calculate a sum of certain records? sickboy Shell Programming and Scripting 10 06-10-2005 11:43 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-08-2008
koti_rama koti_rama is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 50
calculate from three files

Hi all
I have 3 three files like:
file1:

1|100
2|200
3|300
4|400
5|500

file2:
1|200
2|200
3|600
4|800


file3:
1|300
2|100
3|200


i would like out put file like:
1|100|200|300|0
2|200|200|100|100
3|300|600|200|700
4|400|800|0|1200


senario:

i wolud like

file1.column2+file2.cloumn2-file3.cloumn2

please help me on this.
  #2 (permalink)  
Old 01-08-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,426
what have you tried?
  #3 (permalink)  
Old 01-08-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj -------
  
 

Join Date: Feb 2007
Location: Cochin/Singapore
Posts: 515
Code:
paste file1 file2 file3 |sed 's/|/ /g'|awk '{ if ($6=="") $6=0;if ($4=="") $4=0; if ($2=="") $2=0;print $1 "|" $2 "|" $4 "|" $6"|"$2+$4-$6;}'
Output:

Quote:
1|100|200|300|0
2|200|200|100|300
3|300|600|200|700
4|400|800|0|1200
5|500|0|0|500
  #4 (permalink)  
Old 01-08-2008
koti_rama koti_rama is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 50
thanks......
  #5 (permalink)  
Old 01-08-2008
jaduks's Avatar
jaduks jaduks is offline
Registered User
  
 

Join Date: Aug 2007
Location: Assam,India
Posts: 166
$ paste -d "|" filex filey filez | awk '
> BEGIN{OFS=FS="|"} {print $1,$2,$4,$6,$2+$4-$6}
> ' | awk 'BEGIN{OFS=FS="|"}{ for(i=0;i<=NF;i++)
> if ( $i == "" )
> $i=0
> print $0}'


<Output>
1|100|200|300|0
2|200|200|100|300
3|300|600|200|700
4|400|800|0|1200
5|500|0|0|500
  #6 (permalink)  
Old 01-08-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,794
Another one:

Code:
awk '
!f { f2[$1] = $2; next }
f == 3 { f3[$1] = $2; next }
f == 1 { $3 = (f2[$1] ? f2[$1] : 0)
    $4 = (f3[$1] ? f3[$1] : 0)
    $5 = $2 + f2[$1] - f3[$1]
}1' FS="|" OFS="|" file2 f=3 file3 f=1 file1
Sponsored Links
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 10:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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