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 > UNIX for Advanced & Expert Users
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 09-03-2008
user_prady user_prady is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 163
merge two files in ascending order

Hello Friends,

I want to merge two files in ascending order on the first field. And if the first field matches sort on 3rd field i.e, TXADDR should come ahead of RXADDR .

file1
Code:
      9 : TXADDR  : 00000000
     65 : TXDATA  0000000000000011
     83 : TXDATA  0000000000000012
    453 : TXADDR  : 00000000
    509 : TXDATA  0000000000000001
    527 : TXDATA  0000000000000002
    879 : TXADDR  : 00000020
     934 : TXDATA  0000000000000011
     953 : TXDATA  0000000000000012
     971 : TXDATA  0000000000000013
file2
Code:

        9 : RXADDR  : 00000001
      65 : RXDATA  0000000000000011
      83 : RXDATA  0000000000000012
     102 : RXDATA  0000000000000013
     453 : RXADDR  : 00000000
     509 : RXDATA  0000000000000001
     527 : RXDATA  0000000000000002
     546 : RXDATA  0000000000000003
     879 : RXADDR  : 00000020
     934 : RXDATA  0000000000000011
     953 : RXDATA  0000000000000012
     971 : RXDATA  0000000000000013
     990 : RXDATA  0000000000000014
WIth the below command I able to sort and merge on the first field.
Code:
sort -n file1 file2 > file3
In file3 I expect when the first column matches it should give priority to the 3rd column i.e RXADDR & RXDATA.
So in my case the output should be
Code:
      9 : TXADDR  : 00000000
      9 : RXADDR  : 00000001
    65 : TXDATA  0000000000000011
    65 : RXDATA  0000000000000011
I dont know how sort with multiple key with sort pls suggest a option for that. or any other soln.

Regards,
user_prady

Last edited by user_prady; 09-04-2008 at 12:17 AM..