|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
merge two different files
HI I have input file as Code:
date 22jan2011 calc 0 667788.1 998877.2 vals 1 222 444 666 777 999 vals 2 222 444 666 777 999 vals 3 222 444 666 777 999 next file as Code:
date 22jan2011 calc 22 0 0 vals 1 222 444 666 777 999 vals 2 222 444 666 777 999 vals 3 222 444 666 777 999 want the output as: Code:
calc 22 667788.1 998877.2 vals 1 222 444 666 777 999 vals 2 222 444 666 777 999 vals 3 222 444 666 777 999 any help please!!!! thanks in advance Last edited by vbe; 02-05-2012 at 03:30 AM.. Reason: code tags |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Hi Indra2011,
1.- Remove date. 2.- Sum values of 'calc' row. 3.- Print all other rows from any file. Is like that? Regards, Birei |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
any help!!!!
Quote:
any help...!!!! any script with anyone!!!! |
|
#4
|
|||
|
|||
|
Here's a simple awk that will do what Birei suggested: Code:
awk '
/date/ { next; }
/calc/ {
sum[1] = 0;
for( i = 2; i <= NF; i++ )
sum[i] += $(i);
next;
}
NR == FNR {
hold[++hidx] = $0;
next;
}
END {
printf( "calc\t" );
for( i = 2; i <= length( sum ); i++ )
printf( "%.1f\t", sum[i] );
printf( "\n" );
for( i = 1; i <= hidx; i++ )
printf( "%s\n", hold[i] );
}
' |
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| merge files | dvah | Shell Programming and Scripting | 8 | 03-22-2011 07:14 AM |
| Merge files of differrent size with one field common in both files using awk | shashi1982 | Shell Programming and Scripting | 2 | 03-03-2009 06:12 AM |
| how to merge these two files? | fedora | Shell Programming and Scripting | 3 | 02-12-2008 05:45 PM |
| use of sed over cat to merge files | miwinter | UNIX for Advanced & Expert Users | 2 | 11-28-2007 12:36 PM |
| help in merge files | u263066 | Shell Programming and Scripting | 5 | 07-24-2006 03:24 AM |
|
|