![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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. |
|
||||
|
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;}'
Quote:
|
|
|||||
|
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 | ||
|
|