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
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
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.
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
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
The following will sort first by the first key, numerically, and then by the second key alphabetically:
sort -k1,1n -k2,2 file1 file2 > file3
use this code:
sort -n -k 1 my1 my2
Actually, you'll want -k3,3 not -k2,2... but you probably figured that out yourself!
Thanks for your kind replies , but both the command outputs the same as
the command
sort -n file1 file2 > file3
I want to reverse the third column so that TXADDR/TXDATA comes before RXADDR/RXDATA when the first column matches . The above commands gives me the reverse..
annihilannic:
The following will sort first by the first key, numerically, and then by the second key alphabetically:
sort -k1,1n -k2,2 file1 file2 > file3
Thanks for your reply But I want to sort reverse for the second key ..
Code :
sort -t":" -k1,1n -k2,2 file1 file2
Output:
Ok..If you need it in ev order of second col,
sort -t":" -k1,1n -k2,2r file1 file2
O/p:
Oh oh . I think I am misguiding you all .
Desired Output :
9 : TXADDR : 00000000
9 : RXADDR : 00000001
65 : TXDATA 0000000000000011
65 : RXDATA 0000000000000011
83 : TXDATA 0000000000000012
83 : RXDATA 0000000000000012
102 : RXDATA 0000000000000013
453 : TXADDR : 00000000
453 : RXADDR : 00000000
509 : RXDATA 0000000000000001
509 : TXDATA 0000000000000001
527 : TXDATA 0000000000000002
527 : RXDATA 0000000000000002
546 : RXDATA 0000000000000003
879 : TXADDR : 00000020
879 : RXADDR : 00000020
....................
......................
again thanks a ton for your time..
Regards,
user_prady
Have you tried the seond one which I posted..?
Oh sorry I m not aware of the second page ..
Anyway thanks a lot ..
Thats the output I really want ..
Thanks & Rgds,
user_prady