Sponsored Content
Top Forums UNIX for Advanced & Expert Users merge two files in ascending order Post 302232098 by user_prady on Wednesday 3rd of September 2008 10:44:24 PM
Old 09-03-2008
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 01:17 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sort / ascending order

What's the command to sort a file in ascending order and redirect the output to another file? Thanks!!!!!! (1 Reply)
Discussion started by: gyik
1 Replies

2. UNIX for Advanced & Expert Users

Display modified files in ascending order

Hello, i want to display modified files in descending order. "ls -t" will display modified files in descending order. pls help. (1 Reply)
Discussion started by: balareddy
1 Replies

3. Shell Programming and Scripting

Ascending order within text

I appreciate all the help that I've already received but am running into one problem. I can find how to add something before a file with ascending numbers but not like this. I basically have a file that looks like this: 100 101 102 103 104 I need to add the following before each line with... (5 Replies)
Discussion started by: kerpm
5 Replies

4. Shell Programming and Scripting

Ascending order

How can I check if array is in ascending order? ---------- Post updated at 01:53 PM ---------- Previous update was at 01:25 PM ---------- Done it now (0 Replies)
Discussion started by: kristinu
0 Replies

5. Shell Programming and Scripting

Help printing files in ascending order of the fi le size (in bytes)

Hey guys I'm new to unix and need help printing files in a specified directory according to size in bytes as well as files with equal bites in alphabetical order the part i have done so far prints out all files in the directory as well as setting a time limit in which they have been modified ... (2 Replies)
Discussion started by: wessy
2 Replies

6. Shell Programming and Scripting

Merge all the files in a folder in FIFO order

Hi All, I have to merge the data in all the files in a folder such that the data of the earliest file come first then the second file's data and so on. Please help. Thanks. (22 Replies)
Discussion started by: unankix
22 Replies

7. UNIX for Advanced & Expert Users

How to takes the missing files in ascending order

Hi am using unix aix we have a lots of files which comes from server and fetch in one directory. the files will be in the format as File name as : ------------- pprr0103 (01 as date and 03 as month) pprr0203 pprr0603 ... ... pprr3103 pprr0304 Outputs:- Missing files as... (2 Replies)
Discussion started by: Venkatesh1
2 Replies

8. UNIX for Dummies Questions & Answers

Strings in ascending order

Hi, I have a sequence which has 30000 strings which looks like this >string2991 234445 >string224 470561 >string121 675386 >string4098 177229 >string8049 255838 >string8 672382 >string1115 578415 I want it to be arranged in ascending order >string8 672382 >string121... (5 Replies)
Discussion started by: siya@
5 Replies

9. Shell Programming and Scripting

Unable to list files in ascending order

Hi ! I am just trying to list my files in ascending order so that in some other software, I just want merge with some modification, when I list its coming like this new-10.txt new-11.txt new-12.txt new-13.txt new-14.txt new-15.txt new-16.txt new-17.txt new-18.txt new-19.txt... (2 Replies)
Discussion started by: nex_asp
2 Replies

10. Shell Programming and Scripting

How to list files in ascending order?

Hi, I need to list files in ascending order. Filenames are in format inpTDT_1, inpTDT_2, inpTDT_3 and so on. I want to list them in the ascending order based on the digit after underscore and send the output to a file. Please help (5 Replies)
Discussion started by: Neelkanth
5 Replies
JOIN(1) 						      General Commands Manual							   JOIN(1)

NAME
join - relational database operator SYNOPSIS
join [-an] [-e s] [-o list] [-tc] file1 file2 DESCRIPTION
Join forms, on the standard output, a join of the two relations specified by the lines of file1 and file2. If file1 is `-', the standard input is used. File1 and file2 must be sorted in increasing ASCII collating sequence on the fields on which they are to be joined, normally the first in each line. There is one line in the output for each pair of lines in file1 and file2 that have identical join fields. The output line normally con- sists of the common field, then the rest of the line from file1, then the rest of the line from file2. Fields are normally separated by blank, tab or newline. In this case, multiple separators count as one, and leading separators are dis- carded. These options are recognized: -an In addition to the normal output, produce a line for each unpairable line in file n, where n is 1 or 2. -e s Replace empty output fields by string s. -o list Each output line comprises the fields specified in list, each element of which has the form n.m, where n is a file number and m is a field number. -tc Use character c as a separator (tab character). Every appearance of c in a line is significant. SEE ALSO
sort(1), comm(1), awk(1). BUGS
With default field separation, the collating sequence is that of sort -b; with -t, the sequence is that of a plain sort. The conventions of join, sort, comm, uniq, look and awk(1) are wildly incongruous. 7th Edition April 29, 1985 JOIN(1)
All times are GMT -4. The time now is 08:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy