merge two text files of different size on common index


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting merge two text files of different size on common index
# 8  
Old 05-01-2011
I don't think there is a problem here. If you see your a1 input header it is

Quote:
id filePath DiscAtom MultMole NoAtType NoBdType AromFlag SuspectN NHp1Flag NHp2Flag NHp3FLAG ONegFLAG SUMEST SUMCHI SUMKAPPA fw nasH nasB nasC nasN nasO nasF nasSi nasP nasS nasCl nasBr nasI nasNBIO nasHet SSOAmid1 SSOAmid2 SSOAmid3 SN1SO2N2 SN1SO2N3 SN2SO2N2 SN2SO2N3 SN3SO2N3 sumSO2Am
and a2 header

Quote:
id filePath SUB_ID SOURCE ChBrg_REGID
and the output

Quote:
id filePath DiscAtom MultMole NoAtType NoBdType AromFlag SuspectN NHp1Flag NHp2Flag NHp3FLAG ONegFLAG SUMEST SUMCHI SUMKAPPA fw nasH nasB nasC nasN nasO nasF nasSi nasP nasS nasCl nasBr nasI nasNBIO nasHet SSOAmid1 SSOAmid2 SSOAmid3 SN1SO2N2 SN1SO2N3 SN2SO2N2 SN2SO2N3 SN3SO2N3 sumSO2Am SUB_ID SOURCE
SUB_ID and SOURCE is not repeated anywhere.

If you want SUB_ID and SOURCE at 3rd and 4th column, then change the code accordingly.

Post the code you use, something is wrong in that!

regards,
Ahamed
# 9  
Old 05-01-2011
Quote:
Originally Posted by ahamed101
If you want SUB_ID and SOURCE at 3rd and 4th column, then change the code accordingly.
That's more or less what I am trying to figure out how to do. I can get the three cols I want, but they are the last three, not cols 3 4 and 5. There is also a blank col.

Just to clarify, based on the command (different from the last post)
Code:
awk 'NR==FNR{a[$2]=$0;next;}{if ($2 in a){split(a[$2],b," *");printf "%-2s\t%-15s\t%-10s\t%-15s\t%-10s\t%-10s\t%-10s\n",b[1],b[2],$3,$4,$5,b[3],b[4],b[5]}}' a1_temp.txt a2_temp.txt  > output_temp.txt

I assume that in the print statement, $3 refers to the 3rd field of file a1_temp, and b[1] refers to the 1st field of file a2_temp???

If that is correct, in the printout I should get cols 1 and 2 of a2_temp (b[1],b[2]), which should be "id", "filePath". Then I should get cols 3, 4, and 5 from a1_temp, followed by cols 3,4, and 5 from a2_temp. Instead, I am getting all 39 cols from a1_temp, followed by a blank col, followed by the three cols I want from a2_temp. This isn't a disaster, as I can further edit the file with cut, but I would like to better understand the syntax of what I'm trying to do here.

LMHmedchem
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge multiple tab delimited files with index checking

Hello, I have 40 data files where the first three columns are the same (in theory) and the 4th column is different. Here is an example of three files, file 2: A_f0_r179_pred.txt Id Group Name E0 1 V N(,)'1 0.2904 2 V N(,)'2 0.3180 3 V N(,)'3 0.3277 4 V N(,)'4 0.3675 5 V N(,)'5 0.3456 ... (8 Replies)
Discussion started by: LMHmedchem
8 Replies

2. UNIX for Dummies Questions & Answers

Merge selective columns from files based on common key

Hi, I am trying to selectively merge two files based on keys reported in the 1st column. File1: #file1-header1 file1-header2 111 qwe rtz uio 198 asd fgh jkl 165 yxc 789 poi uzt rew 89 lkj File2: #file2-header2 file2-header2 165 ghz nko2 ... (2 Replies)
Discussion started by: dovah
2 Replies

3. Shell Programming and Scripting

Merge multiple files with common header

Hi all, Say i have multiple files x1 x2 x3 x4, all with common header (date, time, year, age),, How can I merge them to one singe file "X" in shell scripting Thanks for your suggestions. (2 Replies)
Discussion started by: msarguru
2 Replies

4. Shell Programming and Scripting

Find matched patterns in a column of 2 files with different size and merge them

Hi, i have input files like below:- input1 Name Seq_ID NewID Scores MT1 A0QZX3 1.65 277.4 IVO A0QZX3 1.65 244.5 HPO A0QZX3 1.65 240.5 RgP A0Q3PP 5.32 241.0 GX1 LPSZ3S 96.1 216.9 MEL LPSS3X 4.23 204.1 LDD LPSS3X 4.23 100.2 input2 Fac AddName NewID ... (9 Replies)
Discussion started by: redse171
9 Replies

5. Shell Programming and Scripting

Merge files based on both common and uncommon rows

Hi, I have two files A (2190 rows) and file B (1100 rows). I want to merge the contents of two files based on common field, also I need the unmatched rows from file A file A: ABC XYZ PQR file B: >LMN|chr1:11000-12456: >ABC|chr15:176578-187678: >PQR|chr3:14567-15866: output... (3 Replies)
Discussion started by: Diya123
3 Replies

6. Shell Programming and Scripting

script to merge two files on an index

I have a need to merge two files on the value of an index column. input file 1 id filePath MDL_NUMBER 1 MFCD00008104.mol MFCD00008104 2 MFCD00012849.mol MFCD00012849 3 MFCD00037597.mol MFCD00037597 4 MFCD00064558.mol MFCD00064558 5 MFCD00064559.mol MFCD00064559 input file 2 ... (9 Replies)
Discussion started by: LMHmedchem
9 Replies

7. UNIX for Dummies Questions & Answers

Merge two files with common IDs but unequal number of rows

Hi, I have two files that I would like to merge and think that there should be a solution using awk. The files look something like this: file 1 IDX1 IDY1 IDX2 IDY2 IDX3 IDY3 file 2 IDY1 dataA data1 IDY2 dataB data2 IDY3 dataC data3 Desired output IDX1 IDY1 dataA data1 IDX2 ... (5 Replies)
Discussion started by: katie8856
5 Replies

8. UNIX for Dummies Questions & Answers

Writing a loop to merge multiple files by common column

I have 100 data files labelled 250.1.txt through 250.100.txt. The second column of the data files partially match (there is about %90 overlap). Each data file has 4 columns. I want the merge all these text files by the matching values in the second column. In the output, the first column should... (1 Reply)
Discussion started by: evelibertine
1 Replies

9. Shell Programming and Scripting

How to remove common file names from text files

I'm running on freebsd -- with a default shell of csh. I have two files named A and B. Each line of each file contains a file name. How can I write a script that removes all the file names in file B from A. I tried to use perl to create a huge regular expression with "|" separating the file... (2 Replies)
Discussion started by: siegfried
2 Replies

10. Shell Programming and Scripting

Merge files of differrent size with one field common in both files using awk

hi, i am facing a problem in merging two files using awk, the problem is as stated below, file1: A|B|C|D|E|F|G|H|I|1 M|N|O|P|Q|R|S|T|U|2 AA|BB|CC|DD|EE|FF|GG|HH|II|1 .... .... .... file2 : 1|Mn|op|qr (2 Replies)
Discussion started by: shashi1982
2 Replies
Login or Register to Ask a Question