Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Search Forums:



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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-05-2012
Registered User
 

Join Date: Apr 2011
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old 02-05-2012
Registered User
 

Join Date: Oct 2010
Location: Bilbao, Spain
Posts: 574
Thanks: 8
Thanked 157 Times in 155 Posts
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  
Old 02-05-2012
Registered User
 

Join Date: Apr 2011
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
any help!!!!



Quote:
Originally Posted by Indra2011 View Post
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
---------- Post updated at 10:15 AM ---------- Previous update was at 10:14 AM ----------

any help...!!!!
any script with anyone!!!!
    #4  
Old 02-05-2012
agama agama is offline Forum Advisor  
Always Learning
 

Join Date: Jul 2010
Location: earth>US>UTC-5
Posts: 1,210
Thanks: 86
Thanked 405 Times in 389 Posts
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
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 04:26 AM.