perl - Merging two files with condition on two columns -


I have two files of type:

File1.txt
  1 117458 rs184574713 rs184574713 1 119773 rs224578963 rs224500000 1 120000 rs224578874 rs224500045 1 120056 rs60094200 rs60094200 2 120056 rs60094536 rs60094536 File <. 2 txt  1 0 119 600 C 0 233 150 122 1 119 600 119 800 D 0 205,92,92 1 119 800 120 400 F 0 192 192 192 2 120 400 122 000 B 0 128 128 128 2 126 800 133 200 A 0 192,192,192   

I want to first file Add the information contained in the second file in the first column match in both the files, while the file is in 1.txt other This column should come in interval, which is displayed in file2.txt between 2 and 3. So that the output should look like this:

  1 117458 rs184574713 rs184574713 c233,150,122 1 119773 rs224578963 rs224500000 d 205,92,92 1 120000 rs224578874 rs224500045 f 0 192,192,192 1 120056 rs60094200 rs60094200 f 0 192,192,192 2 120,440 rs60094536 rs60094536 b 128128128   

Please awk me / perl .. or any other script.

Try this..>

  $ awk 'NR == FN R {a [$ 1, $ 2, $ 3] = $ 4 FS $ 5 FS $ 6, for the next} {(a x) {split (x, tmp, SUBSEP); ($ 1 == tmp [ 1] & amp; amp; amp; amp; $ 2 & gt; = tmp [2] in & amp; amp; $ 2 & lt; = tmp [3]) $ 0 fs one [x]}} '2 file1 Print 1 117458 rs184574713 rs184574713 C23,3,150,122 1 119773 rs2245789 63 rs224500000 D 0 205,92,92 1 120000 rs224578874 rs224500045 F 0 1 9 2, 1 9 52, 1 120056 rs60094200 rs60094200 F 0 9 2, 1 9 52, 1 9 0   
  • each of you can read column 2, column 2 and 3 of the first file 4,5 and indexed array of values ​​of 6.
  • the second file, you will see in your array For the key, you split the key and check the position of the first column matching and see the second column in the range.
  • If the position is correct, then you print the entire line from file 1 after the value of the array.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -